Hari's Corner
Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and thenPython Gtk HOWTO: cell rendering a Treeview created in Glade
Filed under:
Tutorials and HOWTOs by
Hari
Posted on Fri, May 21, 2010 at 14:11 IST (last updated: Tue, May 25, 2010 @ 08:25 IST)
In this series | Next > |
gtk.CellRenderer
to a gtk.TreeViewColumn
for a tree view that was created in Glade.
The steps are not obvious because most of the tutorials out there are for pure GTK code and assumes all the objects are created programmatically and not from the GtkBuilder XML file.
Simply the steps are:
- Add a column to the TreeView in Glade. This is done by editing the treeview not the tree model object. Right click on the tree view object and click on Edit... in the context menu. Then add a column from the Hierarchy tab.
- Now associate a ListStore or any other tree model with the tree view. This can be done either in Glade or programmatically. Take your pick. I prefer to do it in Glade because you can create columns for the tree model as well.
- Now in the Glade program add a cell renderer to the column and associate it with the column number in the model as follows. Place something like the following piece of code somewhere in your initialization code (obviously the variable names/attributes will have to change
It's all a bit confusing and irritating to have to deal with all this and I personally think that GTK's treeview control is a royal pain in the rear for programmers, especially when used in conjunction with Glade. Half the stuff is done in the Glade interface and the rest programmatically. This is a mess and should be a high priority for the GTK programmers to rectify: either improve Glade or simplify gtk.TreeView.# Get the TreeViewColumn object associated with the tree view - self.ui is a gtk.Builder object # in this case the index is 0 col = self.ui.get_object ("tree_view").get_column (0) # Create a text cell renderer cell = gtk.CellRendererText () # Add the cell renderer to the TreeViewColumn col.pack_start (cell) # Attributes for the column - make it display text of column 0 # from the model col.add_attribute (cell, "text", 0)
In this series
- Python Gtk HOWTO: deleting multiple selected items from a gtk.TreeView
- Python Gtk HOWTO: cell rendering a Treeview created in Glade
Comments closed
The blog owner has closed further commenting on this entry.
2 comment(s)
Comment by xingmin (visitor) on Sun, Aug 29, 2010 @ 06:46 IST #
Comment by Nick (visitor) on Mon, May 7, 2012 @ 20:30 IST #