As I was playina with the new concepts of Lists in Gtk4, I have conceptualized how this works, but please correct me if something is wrong:

  1. You populate a GLib.ListModel (or GLib.ListStore) with your data.
  2. one can change the selection method by passing this model to Gtk.SelectionModel.
  3. Sorting can be done by creating a Gtk.Sorter and passing the model with the sorter to a Gtk.ListSortMode.
  4. you create a factory responsible for populating ListItem and how should they be displayed.
  5. you create one of the widgets capable of displaying lists passing the model and the factory to it, model here means the sorted/selected model.

My question is, why the following list always ignore the Selection method, irrelevant which one I choose, NoSelection, SingleSelection or MultiSelection.

        var color_model = new Gtk4Demo.ColorListModel (4096);
        var factory = new Gtk.SignalListItemFactory ();
        // The following always displayes single selection no matter which selection method I choose?
        var selection = new Gtk.NoSelection (color_model);

        var numeric_sorter = new Gtk.NumericSorter (new Gtk.PropertyExpression (typeof (Gtk4Demo.ColorWidget), null, "red"));
        numeric_sorter.set_sort_order (Gtk.SortType.DESCENDING);
        var sorters = new Gtk.SortListModel(selection, numeric_sorter);
        factory.setup.connect (setup_colorlist_cb);
        gridview.model = sorters;
        gridview.factory = factory;

Is there anything untrue regarding my ideas?


If the model you pass to the GtkGridView (same for list view and columnview) is not a GtkSelectionModel, it wraps it in a GtkSingleSelection. In your example, you create a noselection, but then you ‘hide’ it from the grid view by wrapping it in a sortmodel.

Things will work if you change your model setup to put the GtkNoSelection as the outermost model.

@matthiasc Thank you very much for clarification.

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