GTK4 Treeview Popover Menu

How can I show a Popover menu when there is a right-click on a row in a treeview, or if the context menu key is pressed?

It seems there was once a “button-release-event” that could be connected, but that seems gone now.

For right mouse button:

1 - Create a new Gtk.GestureClick, then set its button to 3 (right mouse button).

2 - Create a function in the widget displayed in the treeview to display the menu when Gtk.GestureClick happens .

3 - Connect the “released” signal from Gtk.GestureClick with this function.

For a pressed key:

Basically the same thing, but item 1 will use a Gtk.EventControllerKey, and in item 3 the connected signal will be “key-released”.

If you are using a Gtk.SignalListItemFactory, items 1 and 3 can be done in the bind phase.

On a side note, “button-release-event” was for Gtk3, in Gtk4 we must use GtkEventControllers for capturing events.

See Gtk – 4.0: Migrating from GTK 3.x to GTK 4 for the old/new equivalences.

Thanks! I understand that and it works. :slightly_smiling_face: :slightly_smiling_face:

@gwillems Another Rust / Gtk Bookmark to add to my ever growing collection. :slightly_smiling_face:

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