Re: Packing a Text and Pixbuf renderer into the same cell of a tree view



Tommi Komulainen wrote:
On Sun, 2004-06-13 at 13:48, ext Darryl Luff wrote: 

Does anyone have some sample code for this? I've found lots of text that says 
'just pack a pixbuf renderer and a text renderer into the same cell'. But I 
don't understand how you set which pixbuf to display in each cell for these 
two cases:


Totally untested code follows, but should get the idea across..  There's
lots of example code in gtk-demo and tests, but IMHO there should be
more concrete examples in the API reference.


Thanks Tommi. I have certainly found it hard to find gtk samples.
Usually I look for an app that does what I want then grab the source for
it and see how they did it. But I didn't have any for this!



1.    Where a column has the same image displayed next to the text in each cell, 


renderer = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, renderer, FALSE);
g_object_set (renderer, "pixbuf", the_pixbuf, NULL);

Ok, so the renderer has a global setting as well as the per-column settings.

renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (column, renderer, "text", COL_TEXT);



2.    Where a column has a different image displayed next to the text in each 
cell.


Replace the g_object_set() above with:

gtk_tree_view_column_add_attribute (column, renderer, "pixbuf", COL_PIXBUF);


My main problem was forgetting that the 'column' variable on the API
calls really has nothing to do with the physical column number. I
couldn't see how you could address two renderers with the same column
number. But you dont, the 'column' is really an arbitrary index and has
nothing to do with the actual column number.

Thanks for the help!

Darryl.



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