Subclassing Gtk::Stack to create a "StackView" for a SingleSelection model

I’m using a Gkt::DropDown widget to switch between pages in a Stack, because I have too many items for a StackSwitcher to be appropriate. My current solution is very ugly, but I think a shared Gtk::SelectionModel would let me do things in a much cleaner, more flexible way. I want to create a “StackView” which uses a ListItemFactory to create all the widgets that it switches between. The StackView and the DropDown could then share the same underlying list model, but use their own ListItemFactories to produce appropriate views of the items. When the DropDown changes the selected item in the SelectionModel, the StackView can change which page is showing.

In order to have an accurate size request, the StackView will need to create and bind widgets for all items in the list model immediately (rather than when the widgets become visible, like a conventional ListView). This means that it won’t be necessary to un-bind widgets.

I would like to implement the StackView in a way which is compatible with existing ListItemFactory implementations, but I’ve noticed the factory type doesn’t provide public methods for requesting & binding new widgets. My backup plan is to create my own widget factory type, with a simpler interface that binds widgets on construction. Is there any official way to create custom ListView-like widgets in C++?

I started working on the implementation, but I discovered a wrinkle in my plan: Gtk::DropDown doesn’t use a Gtk::SingleSelection model, so it wouldn’t actually control which page is showing without extra logic to keep the selection model in sync.

I completed my implementation using a custom “DropDownView” class, and it works nicely for my purposes. I posted a feature request because I think DropDownView’s SelectionModel support could be useful in other situations, and I noticed the DropDown code already uses a SingleSelection internally.

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