How can i get the expanded/collapsed items in the new GtkTreeListModel implementation?

I know the GtkTreeListModel etc. is still work in progress.

But do we really have no way to track or query which items are expanded? I would love to save the expanded state during sessions (program sessions or sessions between kills of the container widget).

This is done using Gtk.TreeExpander, which you must use to create the widget that will be displayed in the list.

1 Like

Ok,but why is this done via actions and not signals?
No surprise i could not find this one liner hidden in the API doc.
What is the action parameter? Why is this not documented.

Same why i dont understand why ā€˜GtkTreeListModelCreateModelFuncā€™ is designed as a constructor function and not a signal.

My best guess would to avoid the function changing at an inconvenient time?

Also i donā€™t think ā€˜TreeListModelCreateModelFuncā€™ is even useful in this case.

If you need to know if any given row is expanded i would probably use GtkTreeListRowā€™s expanded property.

What exactly are you doing? Can you post the code?

In Gtk4, a tree list is composed of several elements:

Data Object: an object to hold the data to be displayed (a string that will be displayed like an item, for example).

List: A Gio.ListStore or other list object that will contain the data objects.

Selection: the type of Gtk.Selection that can be made in the component (none, singleā€¦), a List needs to be set as the model of the Gtk.Selection.

ItemFactory: an ItemFactory will create a widget to be displayed in the ListView (a Gtk.Label to display a string like an item, for example), and will add to it the objectā€™s information in the List (the string that goes in the Gtk.Label). The ItemFactory can do this via signals or through the Builder. Gtk.SignalListItemFactory is easier to understand and creates the widgets through a ā€œsetupā€ function, and connects the data object information to the widget through a ā€œbindā€ function. Both are connected to ItemFactory through its ā€œbindā€ and ā€œsetupā€ signals.

Lastly, you need Gtk.ListView to display the widget created by the ItemFactory. Once all this is created, when you insert a Data Object into the List, the ItemFactory will call the ā€œsetupā€ function, then the ā€œbindā€ function, and the Gtk.ListView will display the widget for that item.

That said, GtkTreeListModelCreateModelFunc serves to create Models on demand to allocate the subitems of a treelist, whenever an item of the treelist is expanded or collapsed there will be a call to GtkTreeListModelCreateModelFunc. In the ā€œbindā€ function, the state of the Gtk.TreeExpander must be connected to its respective Gtk.TreeListRow.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.