【问题标题】:How to use a MenuButton (Gtkmm)如何使用菜单按钮 (Gtkmm)
【发布时间】:2019-12-16 02:01:23
【问题描述】:

我正在尝试使用MenuButton,但它不起作用。

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

它不工作。调用 set_menu() 而不是 set_popup() 也不起作用。 结果:

【问题讨论】:

    标签: gtk gtkmm


    【解决方案1】:

    嗯,没错!您只需拨打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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      相关资源
      最近更新 更多