`GtkPopoverMenu` is a subclass of `GtkPopover` that implements menu behavior.
![An example GtkPopoverMenu](menu.png)
`GtkPopoverMenu` treats its children like menus and allows switching between them. It can open submenus as traditional, nested submenus, or in a more touch-friendly sliding fashion.
`GtkPopoverMenu` is meant to be used primarily with menu models, using [[email protected]_from_model]. If you need to put other widgets such as a `GtkSpinButton` or a `GtkSwitch` into a popover, you can use [[email protected]_child].
For more dialog-like behavior, use a plain `GtkPopover`.
The XML format understood by `GtkBuilder` for `GMenuModel` consists of a toplevel `<menu>` element, which contains one or more ` <item>` elements. Each `<item>` element contains `<attribute>` and `<link>` elements with a mandatory name attribute. `<link>` elements have the same content model as `<menu>`. Instead of `<link name="submenu">` or `<link name="section">`, you can use `<submenu>` or `<section>` elements.
```xml <menu id='app-menu'> <section> <item> <attribute name='label' translatable='yes'>_New Window< /attribute> <attribute name='action'>app.new</attribute> </item> <item> <attribute name='label' translatable='yes'>_About Sunny</attribute> <attribute name='action'>app.about</attribute> </item> <item > <attribute name='label' translatable='yes'>_Quit</attribute> <attribute name='action'>app.quit</attribute> </item> </section> </menu> ```
Attribute values can be translated using gettext, like other `GtkBuilder` content. `<attribute>` elements can be marked for translation with a `translatable="yes"` attribute. It is also possible to specify message context and translator comments, using the context and comments attributes. To make use of this, the `GtkBuilder` must have been given the gettext domain to use.
The following attributes are used when constructing menu items:
The following attributes are used when constructing sections:
The following attributes are used when constructing submenus:
Menu items will also show accelerators, which are usually associated with actions via [[email protected]_accels_for_action], [ id@gtk_widget_class_add_binding_action] or [[email protected]_shortcut].
`GtkPopoverMenu` is just a subclass of `GtkPopover` that adds custom content to it, therefore it has the same CSS nodes. It is one of the cases that add a .menu style class to the popover's main node.
`GtkPopoverMenu` uses the gtk_accessible_role_menu role, and its items use the gtk_accessible_role_menu_item, gtk_accessible_role_menu_item_checkbox or gtk_accessible_role_menu_item_radio roles, depending on the action they are connected to.