I’m writing a Gtk4 application that has a GtkDropDown. I need to populate it with items of label-value pairs. And I think I need to use GListStore for the purpose.
In Gtk3, a similar class GtkListStore was available.
From what I read, GListStore accepts only GType in constructor. Instead of declare the column types in GtkListStore, now I should:
Declare a GType (with an gint value and a gchararray for label); then
Declare a GListStore with item-type set to this new GType; then
Declare a GtkDropDown to use the GListStore as model.
My code is written in Python. And neither of the above steps are known to me. Especially step (1). I found previous answer of how to do this in C code. But I cannot find any example how to do this either in .ui (xml) or Python.
Please advice how I should do this. Or at least where I can find relevant documentation / manual / tutorial. Thanks a lot.
Then, on Python side, define some dict or list to map the string to its value.
The hard way is what you described above: create a custom type, then a custom liststore, then a custom factory to generate the strings to display. But I think it’s overkill here.