I've got 99% 44/100 of everything working. I have a glade file, I use gtkbuilder to render it and voila it comes up. Everything except the data in my treeview liststore. I notice by default the tree view is not visible, and setting that to true makes a box appear in the tree view area, but I can't get any of my liststore items to display in the treeview. I have some default data in the list store defined in glade, and I programmatically add some too, but nothing ever displays. Is there some visible on/off option I'm missing?
Asked
Active
Viewed 1.2k times
16
-
near as I can tell gtkbuilder is not coming up with a cellrenderer for my column (which is defined as gchararray) because when I call get_column_cell_renderer I get NULL back. – stu Nov 29 '10 at 21:12
-
1So how do I set a cell renderer in a column created by gtkbuilder? – stu Nov 29 '10 at 21:12
3 Answers
35
To add a cell renderer to your tree view in Glade, right click on the tree view and select "Edit". This brings up the tree view editor. If you click on the "Hierarchy" tab then you can add or remove columns. Add a column and then right click on it for a menu of cell renderers that you can add. This should do the trick.

ptomato
- 56,175
- 13
- 112
- 165
-
6Good lord it really doesn't have to be this complex. I guess I made the poor assumption that the definition of the tree would be defined by the model. I didn't realize you had to define the model AND specify the columns in the tree control as well. Gargh. Thanks muchly. I still don't get text yet but at least I get the column header and can add rows. – stu Nov 30 '10 at 15:27
-
4Got it working, just had to specify the text of the cell renderer to refer to my liststore column data. – stu Nov 30 '10 at 15:30
-
It just seems wrong that in javascript you can var n = document.createElement('option'); n.text = sel.text; n.value = sel.value; document.getElementById("listbox").options.add(n); and it works. – stu Nov 30 '10 at 15:31
-
1It's because the view and model are separate in GTK+. You could have multiple views on the same data, and show a different set of columns in each. – Bernd Jendrissek Apr 24 '13 at 07:07
-
In current versions of Glade, "Edit" is now on toolbar instead of right-click menu. – kolen Dec 05 '18 at 00:00
8
Just to add to what ptomato said, thought I'd throw in the xml for what I have :
<object class="GtkTreeView" id="portfolio_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">portfolio_liststore</property>
<property name="search_column">0</property>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn4">
<property name="title">ID</property>
<property name="clickable">True</property>
<property name="sort_indicator">True</property>
<property name="sort_column_id">0</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext4"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>

Victor Parmar
- 5,719
- 6
- 33
- 36
-
1I haven't yet figured out how/where to set the 'text' attribute; Though editing the file to add the attribute works! – ThorSummoner Feb 23 '15 at 02:09
-
The glade editor does not seem to be adding the attributes automatically which can lead to the original problem. Setting the text field for a cellrenderer to the index of the store's column that one wants to use solves the problem. Else the renderer is not looking up the values. – AbstractDissonance Aug 16 '17 at 03:54
3
I figured it out... to add "'text' attribute" using glade so you can view your data located in the liststore....
1) Right click your treeview and select "Edit"
2) Click on "Hierarchy" tab
3) Right Click the Column you added and select "Add child Text"
4) On the right side of the window beside "Text:" change unset to the liststore/column text type.

misanthropy
- 41
- 1