g_l
g_l

Reputation: 661

How to make Gtk.ListBoxRow accept right clicks on any area?

Edit: corrected code.

ListBox listBox = new ListBox ();
ListBoxRow row = new ListBoxRow ();
row.add (new Label ("Test row"));
row.button_release_event.connect ((event) => {
    if (event.button == 3) {
        debug ("Right button clicked.\n");
    }
    return false;
});
listBox.add (row);

Doesn't work. Prints nothing. But this other one works fine

ListBox listBox = new ListBox ();
ListBoxRow row = new ListBoxRow ();
row.add (new CheckButton.with_label ("Test row"));
row.button_release_event.connect ((event) => {
    if (event.button == 3) {
        debug ("Right button clicked.\n");
    }
    return false;
});
listBox.add (row);

as it prints the debug message. Is it possible to handle right clicks on the ListBoxRow on any area, regardless of what its children are?

Upvotes: 2

Views: 466

Answers (1)

José Fonte
José Fonte

Reputation: 4114

An option to solve this problem would be to use an Gtk.EventBox as the immediate child of each Gtk.ListBoxRow and then use the EventBox as the container for the rows content:

ListBox listBox = new ListBox ();
ListBoxRow row = new ListBoxRow ();
EventBox box = new EventBox ();
box.add (new Label ("Test row"));
row.add (box);
row.button_release_event.connect ((event) => {
    if (event.button == 3) {
        debug ("Right button clicked.\n");
    }
    return false;
});
listBox.add (row);

Upvotes: 3

Related Questions