GtkDropDown:factory or GtkDropDown:expression must be set

I have following notice when trying to define DropDown model without options (to add them later by object reference and append method)

Either GtkDropDown:factory or GtkDropDown:expression must be set

The model stores Label in listing, seems I should define something here, but not understand what exactly, also can’t find any example:

let model = ListStore::new::<Label>();
DropDown::builder()
    .model(&model)
    .expression(Expression::) // what should be here?
    .build();

UPD. I’ve setup DropDown with following construction, but no ideas why should I define factory or expression manually, when this feature not in use

DropDown::builder()
    .model(&model)
    .factory(&SignalListItemFactory::new())
    .build();

Now understand: Factory implementation wanted only when append new records to ListStore model after DropDown (or similar) widget activation.

Here is related article:

https://gtk-rs.org/gtk4-rs/stable/latest/book/list_widgets.html

And short code example, how do I use it now:

// Init model with custom `GObject` properties
let model = ListStore::new::<Item>();

// Setup item factory to append items after `DropDown` init
let factory = SignalListItemFactory::new();

factory.connect_bind(move |_, gobject| {
    // Cast components
    let list_item = gobject.downcast_ref::<ListItem>().unwrap();
    let item = list_item.item().and_downcast::<Item>().unwrap();

    // Update item with new gtk::Label (or update existing one)
    list_item.set_child(Some(&Label::new(Some(&item.some_property()))));
});

// Init dropdown `GObject`
let dropdown = DropDown::builder().model(&model).factory(&factory).build();

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