GtkEventBox 将信号连接到 Glade 中的 GAction

GtkEventBox connect signal to GAction in Glade

我正在尝试通过 Glade 将 GtkEventBox 的 enter-notify-event 连接到附加的 GAction。使用 GtkInspector 检查 运行 应用程序显示没有连接到 enter-notify-event 信号。

我正在关注 this blog post 其中指出:

You could also set the properties via the .ui file. When you replace the event handlers of clicks with actions you can really streamline your code base.

所以我认为这应该是有可能的。它只提到了 GtkButton 的点击处理程序,但我不明白为什么它应该与其他信号不同。

林间空地:

检查员:

<object class="GtkEventBox" id="service_row">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <signal name="enter-notify-event" handler="test.show-arrow" swapped="no"/>

(complete UI file)

let actions = SimpleActionGroup::new();
let show_arrow = SimpleAction::new("show-arrow", None);
actions.add_action(&show_arrow);
show_arrow.connect_activate(move |_action, _data| {
   println!("enter row2");
});
row.insert_action_group("test", &actions);
// row.connect_enter_notify_event(move |_widget, _crossing| {
//     actions.activate_action("show-arrow", None);
//     Inhibit(false)
// });

通过推荐行中的代码手动激活 GAction 就可以了。当查看 EventBox 时,该操作也会显示在检查器中。

非常感谢任何帮助:)

我认为你做不到。 GtkActionable 仅适用于具有明确用户激活操作的小部件,例如按钮或菜单项。特别是 GtkEventBox 没有实现它。

即使有,此界面也只会为每个 class 管理一个事件,即 activate 操作,而不是您感兴趣的 enter-notify-event .

所以,恐怕您将不得不继续手动连接您的活动。