gtk - 如何使用菜单按钮 (Gtkmm)
问题描述
我正在尝试使用 aMenuButton
但它不起作用。
#include <gtkmm.h>
int main( int argc, char **argv)
{
Glib::RefPtr< Gtk::Application > app = Gtk::Application::create( "App1" );
Gtk::Window window;
Gtk::MenuButton menuButton;
menuButton.set_label("menu button");
Gtk::Menu menu;
Gtk::Label label1("label1");
Gtk::Label label2("label2");
Gtk::MenuItem item1(label1);
Gtk::MenuItem item2(label2);
menu.append(item1);
menu.append(item2);
menuButton.set_popup(menu);
window.add(menuButton);
window.show_all();
return app->run(window);
}
解决方案
嗯,没错!您只需要致电menu.show_all()
:
#include <gtkmm.h>
int main( int argc, char **argv)
{
Glib::RefPtr< Gtk::Application > app = Gtk::Application::create( "App1" );
Gtk::Window window;
Gtk::MenuButton menuButton;
menuButton.set_label("menu button");
Gtk::Menu menu;
Gtk::Label label1("label1");
Gtk::Label label2("label2");
Gtk::MenuItem item1(label1);
Gtk::MenuItem item2(label2);
menu.append(item1);
menu.append(item2);
menu.show_all();
menuButton.set_popup(menu);
window.add(menuButton);
window.show_all();
return app->run(window);
}
推荐阅读
- c# - 如何从 GameObjects Unity 列表中禁用子对象
- javascript - 克隆对象时重新绑定功能的问题
- python-3.x - 上传数据后提交错误
- java - 使用 Docker 将存档添加到 Libre Office
- c# - 在 Web 窗体中创建 Web API 以从 SQL 数据库表中提取
- java - 如何通过 Simba JDBC 驱动程序将二进制 base 64 数据插入 MongoDB?
- sql - 在选择中选择子查询
- python - LSTM 输出 Dense 需要 2d 输入
- java - 应用程序在切换活动时崩溃,构建完成,没有错误
- javascript - 连续循环遍历数组 onClick 并渲染每个元素