Documentation by gtk_list_view tree

I encountered the problem. There is not found the documentation how to set up the tree gtklistview. All so has become hardly. In gtk-demo is not example with new API. I need to build the tree, but I don’t understand how is?


There are some examples in gtk4-demo under the “Lists” category, I recommend the “Application Launcher” and “Weather” demos, they’re quite simple and give a nice overview on how to use listviews.

There is also a small (incomplete) sample in the official API documentation.
See also the overall concept of listviews.

Yes, but it’s not enough. How do I make listview like as treeview with a lot inside elements?

I had previously posted on this forum a conceptual step-by-step guide to creating a tree list view, unfortunately I can no longer find the topic, so I will rewrite it here. You will need:

1 - Gtk.ListView or Gtk.ColunmView - the widget that will display the visible content as a list.

2 - Gio.ListStore or one of its variants - the list that will contain the objects whose information will be used to create rows in the Gtk.ListView.

3 - Gtk.TreeListModel - a model that will determine how the items contained in the Gio.ListStore will be accessed/viewed.

4 - Gtk.NoSelection, Gtk.SingleSelection or Gtk.MultiSelection - will determine whether the items displayed in Gtk.ListView can be selected and how.

5 - Gtk.SignalListItemFactory or Gtk.BuildListItemFactory - a function that will build a widget to be displayed as a row in the Gtk.ListView. This widget will be populated with the information contained in the Gio.ListStore objects.

6 - GtkTreeExpander - widget that must be included in the widget built by Gtk.SignalListItemFactory to allow row expansion.

7 - Info Object - an object that will be inserted into the Gio.ListStore and that contains the information to be displayed by the rows created by Gtk.SignalListItemFactory.

The process has a few steps, although it is possible to understand them through the documentation, there is a specific step: the Gtk.TreeListModel callback function, which I find difficult to understand without an example. Here is a minimal example of implementing a tree list view in Python.

1 Like

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