MIgrating Tree to ColumnView - Can't get TreeExpander Icon to show -- Solved

I have successfully migrated my TreeView to a ColumnView up to the stage where all the data is bound and shows as required, but the TreeExpander is not showing at all.

The factory set up is below

pub(crate) fn build_tree_column_factory<T: IsA<Object>>(f: fn(Label, &T)) -> SignalListItemFactory {
    let factory = SignalListItemFactory::new();
    factory.connect_setup(move |_, list_item| {
        let label = Label::new(None);
        let expander = TreeExpander::new();
        expander.set_child(Some(&label));
        expander.set_indent_for_icon(true);
        list_item
            .downcast_ref::<ListItem>()
            .expect("Needs to be ListItem")
            .set_child(Some(&expander));
    });

    factory.connect_bind(move |_, list_item| {
        // Get `StringObject` from `ListItem`
        let obj = list_item
            .downcast_ref::<ListItem>()
            .expect("Needs to be ListItem")
            .item()
            .and_downcast::<T>()
            .expect("The item has to be an <T>.");

        // Get `Label` from `ListItem`
        if let Some(widget) = list_item
            .downcast_ref::<ListItem>()
            .expect("Needs to be ListItem")
            .child() {
            let expander = widget.downcast::<TreeExpander>()
                .expect("The child has to be a `Expander`.");

            let widget = expander.child()
                .expect("The child has to be a `Widget`.");
            let label = widget.downcast::<Label>()
                .expect("The child has to be a `Label`.");
            // Set "label" to "value"
            f(label, &obj);
            // get the item from the tree list row
            if list_item.is::<TreeListRow>() {
                let row = list_item.downcast_ref::<TreeListRow>().unwrap();
                expander.set_list_row(Some(row));
            }
        }
    });
    factory
}

Screenshot From 2025-01-16 17-34-54

The data is exactly as I want, but no expander icons :frowning:

After reading TreeExpander source code, I discovered the expander icon is only set if the list_row property of the tree expander is set, which led me to find a bug in my code where that property was not being properly set, due to wrongly downcasting the Ojbject passed to the bind method.

1 Like