The other day I wanted to put both an icon and text in the same GTK+ TreeViewColumn
, and I had absolutely no idea how to do that. So I Google’d and Google’d but had trouble finding any examples. I even downloaded the source code of the Gnome System Monitor – where exactly what I wanted exist – but that was mostly written in C++ which I know very little of.
But I’m stubborn, and after a while I found and example in Python which I managed to interpret. Even though I know very little Python it’s not that hard to follow, and the example was short.
In short what’s needed is packing two CellRenderer
s in the same TreeViewColumn
. Quite logical when you know about it. The example below is in Vala:
- var tree_view = new TreeView ();
- var col = new TreeViewColumn ();
- col.title = title;
- col.resizable = true;
- var crp = new CellRendererPixbuf ();
- col.pack_start (crp, false);
- col.add_attribute (crp, “pixbuf”, 0);
- var crt = new CellRendererText ();
- col.pack_start (crt, false);
- col.add_attribute (crt, “text”, 1);
- tree_view.insert_column (col, –1);
I hacked up a simple application that shows all installed programs – that has a .desktop
entry I guess – in a list (the screenshot above). The sources is available at my Github repository.
Happy coding!