Gtk4 Rust How to get listbox item label text?

I have ListBox with Labels as ListBoxRows.
How to get a label text from selected ListBoxRow?
I’ve tried get Label child with ListBox.selected_row().unwrap().child().unwrap().
But there isn’t any text() or label() functions to get text from child Label widget.

Edit: I found solution.
You need to get Label widget with YourListBox.selected_row().unwrap().property(“child”).
And this Label widget has label() and text() function for getting text from it.
I don’t know why child().unwrap() doesn’t work.

P.S. When you getting child of some widget through this kind of functions
you will get only base class Widget with same name.
To get fully functional specific widget (Label in this case)
you need to downcast your result (remove quotes around ‘<’):

YourListBox.selected_row().unwrap().child().unwrap().downcast::‘<‘gtk::Label’>’().unwrap()

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