I am trying to show a custom context menu when I right click on a row in a TreeView.
treeView.button_press_event.connect ((event) => {
if (event.type == EventType.BUTTON_PRESS && event.button == 3) {
Gtk.Menu menu = new Gtk.Menu ();
Gtk.MenuItem menu_item = new Gtk.MenuItem.with_label ("Add file");
menu.add (menu_item);
menu.show ();
}
});
It doesn't show anything. If I debug a message there I can see the block is being executed when right clicking on a row in the TreeView. I tried show_all () with no success either. popup_at_pointer () is available only on Gtk+ 3.22 and later versions. I am using Gtk+ 3.18.
Is there any way to show a custom menu when right clicking a row on a Gtk.TreeView?