Key/Value for ListModel in DropDown

I want to store keys for text values in list (as ID to process the form depending on user choice)

Seems that DropDown accept ListModel that does not support something else than strings, also I can’t create ListStore because it requires Gobject where I want to hold just key/value pairs as (i64, String) tuple for example

let model = gtk::StringList::new(&[&"value 1", &"value 2"]);
let extra_child = gtk::DropDown::builder().model(&model).build();

Thoughts about external HashTable or Vec storage, but not sure connect_selected_notify will return same index selected as the vector holds.

You’ll have to write a GObject type that contains the integer and the string values; you cannot use a Rust pair or tuple type.

You’ll also likely need properties in order to set up and bind row widgets inside the DropDown factory, so a GObject class for the row data is your only option.

1 Like

Thanks for reply,

found also this article that explains Gobject implementation

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