RE: icons in GtkTreeView




  How can I insert icons in GtkTreeView's rows? I need
folder_opened/folder_closed icons like in XMMS dirbrowser
window. Guys in gtk-devel wrote that this could be a theme
question. So how to set this icon with gtkrc or something?

-- 

First, Make sure that in your gtk_tree_store_new() function you have an
GDK_TYPE_PIXBUF and that (if you have used the gtk-demo as an example)
should correspond to a enumerated COLUMN number, e.g. COL_IMAGE.

Now there are two ways you can do this, you can do it easily by having a
separate column for the image, or you can do it the hardway by packing the
image into the same column as the text you want with it.

First the easy way:

    /* COL_IMAGE */
    renderer_image = gtk_cell_renderer_pixbuf_new ();
    col_offset = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW
(treeview),
                                                             -1, "Image",
                                                             renderer_image,

                                                             "pixbuf",
COL_IMAGE,
                                                             NULL);
  
    column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), col_offset -
1);
    gtk_tree_view_column_set_sort_column_id(column, COL_IMAGE);
    gtk_tree_view_column_set_resizable(column,FALSE);

    /* COL_TEXT */
    renderer_text = gtk_cell_renderer_text_new ();
    col_offset = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW
(treeview),
                                                             -1, "Name",
                                                             renderer_text, 
                                                             "text",
COL_TEXT,
                                                             NULL);
  
    column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), col_offset -
1);
    gtk_tree_view_column_set_sort_column_id(column, COL_TEXT);
    gtk_tree_view_column_set_resizable(column,TRUE);


Second the hard way:

    /* cell renderer's */
    renderer_image = gtk_cell_renderer_pixbuf_new();
    renderer_text = gtk_cell_renderer_text_new();

    column = gtk_tree_view_column_new();

    /* COL_OP_IMAGE */
    gtk_tree_view_column_pack_start(column,renderer_image,FALSE);
    gtk_tree_view_column_add_attribute(column,
                                       renderer_image,
                                       "pixbuf",COL_IMAGE);  

    /* COL_TEXT */
    gtk_tree_view_column_pack_end(column,renderer_text,TRUE);
    gtk_tree_view_column_add_attribute(column,
                                       renderer_text,
                                       "text",COL_TEXT);
    /* set sort id */
    gtk_tree_view_column_set_title(column, "Name");
    gtk_tree_view_column_set_sort_column_id(column, COL_TEXT);
    gtk_tree_view_column_set_resizable(column,TRUE);

    /* insert column */
    gtk_tree_view_insert_column(GTK_TREE_VIEW(treeview),column,-1);

Also, don't forget to set the pixbuf data when adding items so the there IS
an image!

Regards,
Martyn




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