NoBugs
NoBugs

Reputation: 9512

How do I set a listStore model on pre-created listbox from Glade?

Apparently the "proper" way to have items in a GTKListBox or Treeview is constructing with a listStore model, in the constructor. What if I want to use Glade GUI project, in which a list box is already created, and referenced by builder.get_object("appsDocumentListBox")?

Can I set the model after Gtk.builder created the window, or is there a better way to do this?

I'm also wondering what the performance improvement is of using the ListStore vs manually adding with row = Gtk.ListBoxRow(), adding contents and setting ListBox.add(row)? (which does work from a Glade-builder Python window)

Unlike Treeview, apparently Listbox won't set a model after constructor?

>>> l = Gtk.ListBox()
>>> l.set_model
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ListBox' object has no attribute 'set_model'

Upvotes: 0

Views: 1604

Answers (1)

elya5
elya5

Reputation: 2258

You are mixing two things up. You can create a GtkListBox and add GtkListBoxRows to it. There is no need for an extra model here.

There are also GtkListStore and GtkTreeStore. Both of them use a GtkTreeView. The ListStore has a flat hierarchy and the TreeStore can be nested. The GtkTreeView has a set_model function so you can set a model after you created it. You can also create the corresponding model directly in Glade.

If you have complicated widgets that you want to add, the GtkListBox is better suited. For a lot of data which is supposed to be sorted or hierarchically structured, I would rather use a GtkTreeView with a corresponding model.

Upvotes: 2

Related Questions