如何让 Gtk.ListBoxRow 接受任何区域的右键单击?

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

编辑:更正代码。

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);

无效。什么都不打印。但是另一个工作正常

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);

因为它打印调试消息。是否可以在任何区域处理 ListBoxRow 的右键单击,而不管其子项是什么?

解决此问题的一个选项是使用 Gtk.EventBox 作为每个 Gtk.ListBoxRow 的直接子项,然后使用 EventBox 作为行内容的容器:

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);