Simplest way of adding menubar to a gtkmm3 application

In the examples section of the documentation there are several ways and methods of adding a menubar to an application. When I checked them out I noticed that for such a tiny task code required is huge. So I was wondering what would be the simplest way of adding a standard menubar like File, Edit, About… to an application ?

In the past the answer would have been: GtkUIManager, but it’s deprecated in gtk3 and removed in gtk4.

For simple needs GTK 3 has some API for creating a menubar with GMenu. (GMenu is part of GIO, but there are some APIs in GTK too for the widgets). See for example gtk_menu_bar_new_from_model().

For more complex needs, GTK 3 lacks some features. I created the libgedit-amtk library, and in the development version of The GIMP there is something similar (with GimpAction).

Hope that helps.

There is no concept of “a standard menubar” in GTK/mm, so you have to declare exactly which (sub)menus and items you want, and what they should do. Using Gio::Menu with XML definitions is most future-proof if it suits your needs. Manually building menus with GtkMenu(Item) shouldn’t be done in new GTK3 code as those are removed in GTK4.

1 Like

Ok I figured out how to add the bar the old way but XML option is still a pending solution for me. Anyway thanks for the pointer, at least now I have an understanding on which implementation is classified under what conditions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.