En meny

Menyn visas på höger sida av rubrikraden. Den är tänkt att samla mer sällan använda åtgärder som påverkar hela programmet.

Just like the application window, we specify our menu in a ui file, and add it as a resource to our binary.

To make the menu appear, we have to load the ui file and associate the resulting menu model with the menu button that we've added to the headerbar. Since menus work by activating Gio::Actions, we also have to add a suitable set of actions to our application.

Adding the actions is best done in the on_startup() default signal handler, which is guaranteed to be called once for each primary application instance.

Our preferences menu item does not do anything yet, but the Quit menu item is fully functional. It can also be activated by the usual Ctrl-Q shortcut. The shortcut is added with Gtk::Application::set_accel_for_action().

Menyn ser ut så här:

En meny

Källkod