【发布时间】:2021-04-25 16:13:12
【问题描述】:
public class Epoch.CitiesChooser : Gtk.MenuButton {
private Epoch.CitiesSearch cities_search;
construct {
var button_grid = new Gtk.Grid ();
button_grid.column_spacing = 6;
var button_label = new Gtk.Label ("Dimapur");
button_grid.add (button_label);
button_grid.add (new Gtk.Image.from_icon_name ("pan-down-symbolic", Gtk.IconSize.MENU));
add (button_grid);
cities_search = new Epoch.CitiesSearch ();
cities_search.show_all ();
/* Use a event.eventkey.keypress here to add update the label of the menu_button using set_text */
if (cities_search.location_entry.visible) {
key_press_event.connect ((event) => {
stdout.printf ("Keyval: 0x%X\n", event.key.keyval);
if (event.key.keyval == 0xFF57) {
button_label.set_text (cities_search.location_entry.get_text ());
cities_search.location_entry.hide ();
}
return false;
});
}
popover = new Gtk.Popover (this);
popover.width_request = 310;
popover.add (cities_search);
}
}
我想在键盘上按下“结束”键时更新menu_button 的标签。
代码编译没有错误,但信号未连接,stdout.printf ("Keyval: 0x%X\n", event.key.keyval); 不打印任何内容。
标签也没有更新。
【问题讨论】: