How does Gtk.DropDown and Gtk.ColumnView work?

Now I have read the blog about ListView and ListItemFactory (can’t post more than 3 links though) and I have read through the sample in the GTK4 ‘characters’ sample demo, to see how it implements the items into the list. While I can understand some of the C code and rewrite it into other languages (eg. using a GTK4 language binding for C# called Gir.Core), there’s been one part in the code that I’ve kinda struggled to understand properly.

It’s the part where it implements the item. Which that is, adding the item into the list for each and every one of them.

I’m currently working on porting an application called VG Music Studio to the GTK4 GUI to replace the WinForms GUI. So I have attempted implementing something similar to what WinForms does with adding items into the list, but this results in creating an endless amount of call stacks.

So I need to properly understand how the ListItemFactory and ListModel work in adding items, so I can add the items that are generated from the Config class from the Core assembly, and to avoid creating an endless loop of call stacks.

I’m aware this is a language binding that isn’t officially supported by GTK or GNOME, but the C code is pretty similar enough to understand how they operate. I just need to need to understand how different it is from WinForms ObjectCollection in regards to how it adds items into the list and what I need to do to add the entries.

Thank you so much!

Have you read Gtk – 4.0: List Widget Overview and Gtk – 4.0: Tree and List Widget Overview ?

2 Likes

Okay, there are several texts talking about how lists work in GTK4, but I also had some difficulty understanding them until I found a clear example. I will try to explain the concepts. To create a CollumView you will need the following elements:

data object: an object to hold the data to be displayed (a string that will be displayed in a cell, for example).

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

Model: the model is a specific way to interact with objects inside the List. A TreeListModel can create child models on demand, a SortListModel uses a sorter to sort items, etc.

Selection: the type of selection that can be made in the component (none, single…), is created from the model.

ItemFactory: an ItemFactory will create a widget to be displayed in the CollumView (a gtkLabel to display a string in a cell, for example), and will add to it the object’s information in the List (the string that goes in the gtkLabel). 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.

CollumView: will display the widget created by the ItemFactory already with the specific data linked. In the case of the CollumView, each column will have its own 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 CollumView will display the widget for that cell.

1 Like

Pretty sure I have read through them, but I’ll definitely read through them again.

@kriptolix That will definitely help me understand it more easily. I really appreciate everyone’s help. Thank you!

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