在扩展器 (lablgtk) 中捕获 label_widget 中的点击
Capturing clicks in label_widget in expander (lablgtk)
在 lablgtk 中,我有一个 Expander 小部件,我在其中添加了一个按钮作为其标签的一部分,如下图所示:
但是,我无法捕获对此按钮的点击,因为所有这些点击似乎都被 Expander 对象本身捕获。
我什至尝试在扩展器和按钮之间添加一个事件框(类似于推荐用于可点击 GLabel 的方法),但这没有帮助。
有没有办法保证按钮接收到信号?
这里有一个 self-contained 示例来说明这一点:单击按钮只会打印 expander activated!
,但不会显示 button clicked!
.
let main () =
(* create expander, a label_widget, and a button *)
let expander = GBin.expander () in
let expander_label = GMisc.label ~text:"expander" () in
let expander_label_widget = GPack.hbox () in
let button = GButton.button ~stock:`OK () in
(* add button to label_widget, and label_widget to expander *)
expander_label_widget#add expander_label#coerce;
expander_label_widget#add button#coerce;
expander#set_label_widget expander_label_widget#coerce;
(* add events for both the button and the expander *)
ignore (button#connect#clicked
~callback:(fun () ->
Format.printf "button clicked!@."));
ignore (expander#connect#activate
~callback:(fun () ->
Format.printf "expander activated!@."));
(* create window and add expander *)
let window = GWindow.window () in
window#add expander#coerce;
ignore (window#connect#destroy
~callback:(fun () -> GMain.Main.quit ()));
(* show result *)
window#show ();
GMain.Main.main ()
let () =
ignore (GtkMain.Main.init ());
main ()
在 lablgtk 中,我有一个 Expander 小部件,我在其中添加了一个按钮作为其标签的一部分,如下图所示:
但是,我无法捕获对此按钮的点击,因为所有这些点击似乎都被 Expander 对象本身捕获。
我什至尝试在扩展器和按钮之间添加一个事件框(类似于推荐用于可点击 GLabel 的方法),但这没有帮助。
有没有办法保证按钮接收到信号?
这里有一个 self-contained 示例来说明这一点:单击按钮只会打印 expander activated!
,但不会显示 button clicked!
.
let main () =
(* create expander, a label_widget, and a button *)
let expander = GBin.expander () in
let expander_label = GMisc.label ~text:"expander" () in
let expander_label_widget = GPack.hbox () in
let button = GButton.button ~stock:`OK () in
(* add button to label_widget, and label_widget to expander *)
expander_label_widget#add expander_label#coerce;
expander_label_widget#add button#coerce;
expander#set_label_widget expander_label_widget#coerce;
(* add events for both the button and the expander *)
ignore (button#connect#clicked
~callback:(fun () ->
Format.printf "button clicked!@."));
ignore (expander#connect#activate
~callback:(fun () ->
Format.printf "expander activated!@."));
(* create window and add expander *)
let window = GWindow.window () in
window#add expander#coerce;
ignore (window#connect#destroy
~callback:(fun () -> GMain.Main.quit ()));
(* show result *)
window#show ();
GMain.Main.main ()
let () =
ignore (GtkMain.Main.init ());
main ()