Re: Treeview with images problem



Make sure you create the model with the right types first Even though you are using one column, you are effective packing what would be two columns normally into one. To do this you still need a type in the model to support each part packed into the column:

**** code ****

/* columns */
enum
{
 COL_IMAGE = 0,
 COL_NAME,
 COL_COUNT
};

void populate()
{
GtkTreeStore *model;

 /* create tree store */
 model = gtk_tree_store_new(COL_COUNT,
                GDK_TYPE_PIXBUF,
                G_TYPE_STRING);

     if(model != NULL)
       {
         GtkTreeIter iter;

         gtk_tree_store_append(model, &iter, NULL);
         gtk_tree_store_set(model, &iter,
                COL_IMAGE, imageNewFromFile(FILE_GROUPS),
                COL_NAME, name,
                -1);


       }
}

GdkPixbuf *imageNewFromFile(const gchar *filename)
{
 GtkWidget *image;

 if(filename == NULL || strlen(filename) < 1)
   {
     g_warning("imageNewFromFile: filename was NULL");
     return NULL;
   }

 image = gtk_image_new_from_file(filename);

 if(image == NULL)
   g_warning("imageNewFromFile: image was NULL");

 return gtk_image_get_pixbuf(GTK_IMAGE(image));
}

****

I hope this helps,

Regards,

Martyn




Remco Poelstra wrote:

 /* COL_NAME */
 gtk_tree_view_column_pack_end(column,renderer_text,TRUE);
 gtk_tree_view_column_add_attribute(column,
                    renderer_text,
                    "text",COL_NAME);


Hi,

How do I here associate a column from the model with this text renderer? My model has only one column with type G_TYPE_STRING. In the manual they put a '0' in place of the COL_NAME, but that doesn't work for me...

Thanks for the reply,

Remco Poelstra
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list









[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]