GridView deselect (original) (raw)
Hi,
I’m using GtkGridView
in a GTK4 app, what I’m trying to achieve is to deselected all selected items when clicking in a place where there’s no item.
Is there any way to achieve this?
Currently, what I can think of is calling Gtk.SelectionModel
unselect_all
on some signal, but I can’t find any signal matching my needs (ie. that fires when clicking outside any item).
In GTK3, Gtk.IconView
had a method get_item_at_pos
which could be used to determine if a click was outside an item, but this method doesn’t seem to be available in Gtk.GridView
in GTK4. I’ve tried using a Gtk.GestureClick
to capture click events and determine the click position, but I’m struggling to find a reliable way to check if the click is indeed outside any items.
Hi,
Yes, use a GestureClick, then call Gtk.Widget.pick to get the widget under the click coordinates. If it returns the gridview itself (or maybe NULL, I can’t remember), then you clicked in an empty area.
mrlem May 30, 2025, 9:14pm 3
Works like a charm: it does return the Gtk.Gridview
when clicking an empty area. Thanks a lot!