If you create a Liststore and TreeView using Python, then everything works well:

... model = Gtk.ListStore(str, bool) for name in data: model.append([name, True]) treeview = Gtk.TreeView(self.model) col_name = Gtk.TreeViewColumn("Name") cell_name = Gtk.CellRendererText() col_name.pack_start(cell_name, expand=False) col_name.set_attributes(cell_name, text=1) col_bool = Gtk.TreeViewColumn("Bool") cell_bool = Gtk.CellRendererPixbuf() col_bool.pack_start(cell_bool, expand=False) col_bool.set_cell_data_func(cell_bool, render_icon) treeview.append_column(col_bool) treeview.append_column(col_name) ... 

But, if using Glade:

 ... builder = Gtk.Builder() builder.add_from_file("ui.glade") treeview = builder.get_object("treeview") model = treeview.get_model() col_bool = builder.get_object("col-bool") cell_bool = builder.get_object("cell-bool") col_bool.set_cell_data_func(cell_bool, render_icon) for name in data: model.append([name, True]) 

Ui.glade file

 ... <object class="GtkListStore" id="liststore"> <columns> <!-- column-name service --> <column type="gchararray"/> <!-- column-name state --> <column type="gboolean"/> </columns> </object> ... <child> <object class="GtkTreeViewColumn" id="col-name"> <property name="title" translatable="yes">Service</property> <property name="expand">True</property> <child> <object class="GtkCellRendererText" id="cell-name"/> <attributes> <attribute name="text">0</attribute> </attributes> </child> </object> </child> <child> <object class="GtkTreeViewColumn" id="col-bool"> <property name="max_width">25</property> <property name="title" translatable="yes">State</property> <property name="alignment">1</property> <child> <object class="GtkCellRendererPixbuf" id="cell-bool"/> </child> </object> </child> ... 

then when I run model.append, I get a lot of minings:

(myapp: 9434): Gtk-WARNING **: gtk_widget_size_allocate (): try to allocate widget with width -4 and height -9

and then

Segmentation Error

I can not understand what's the matter, everything seems to be right.

Also, if the data is entered into the GdekListStore in the glade file, they are displayed quite normally.

  • Where the declaration is "treeview" from the ui.glade file Does the property <property name = "model"> liststore </ property>? - Yaroslav
  • @Yaroslav, yes, of course. I pointed out that if you enter the data into the model directly into the glade in the <data> section and do not execute the append, then the display is normal. - Sasay
  • And the render_icon function. What is he doing ? Is this function added to ui.glade when initializing a TreeViewColumn? - Yaroslav
  • Sets GdkPixbuf.Pixbuf to cell-bool , different icons depending on the value received from the model. - Sasay
  • In ui.glade there is no connection between the column (col_bool), the cell (cell_bool) and the render_icon function, and the source code has the col_bool.set_cell_data_func (cell_bool, render_icon) connection - Yaroslav

1 answer 1

I did not understand how I got rid of the error. As it seemed to me, the problem is in the parent GtkScrolledWindow , namely in the property resize_mode ( resize_mode Mode) if it is set to immediate .

 <object class="GtkScrolledWindow" id="scrolledwindow"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="resize_mode">immediate</property> <property name="shadow_type">in</property> <property name="min_content_width">350</property> <property name="min_content_height">250</property> <child> <object class="GtkTreeView" id="treeview"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="valign">start</property> <property name="model">liststore</property> ... </object> </child> </object> 

Error segmentation, only without warning'ov.

  • I therefore refused to use the glade, a lot of not documented parameters in the use of the Builder. - Yaroslav