PopoverMenu


Object Hierarchy:

Object hierarchy for PopoverMenu

Description:

[ CCode ( type_id = "gtk_popover_menu_get_type ()" ) ]
public class PopoverMenu : Popover, Accessible, Buildable, ConstraintTarget, Native, ShortcutManager

GtkPopoverMenu is a subclass of Popover that 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 PopoverMenu.from_model. If you need to put other widgets such as SpinButton or Switch into a popover, use a plain Popover.

Menu models

The XML format understood by Builder for MenuModel 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.

<!--language: 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 Builder 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 Builder must have been given the gettext domain to use.

The following attributes are used when constructing menu items: - "label": a user-visible string to display - "action": the prefixed name of the action to trigger - "target": the parameter to use when activating the action - "icon" and "verb-icon": names of icons that may be displayed - "submenu-action": name of an action that may be used to determine if a submenu can be opened - "hidden-when": a string used to determine when the item will be hidden. Possible values include "action-disabled", "action-missing", "macos-menubar". This is mainly useful for exported menus, see set_menubar. - "custom": a string used to match against the ID of a custom child added with add_child, add_child, or in the ui file with `<child type="ID">`.

The following attributes are used when constructing sections: - "label": a user-visible string to use as section heading - "display-hint": a string used to determine special formatting for the section. Possible values include "horizontal-buttons", "circular-buttons" and "inline-buttons". They all indicate that section should be displayed as a horizontal row of buttons. - "text-direction": a string used to determine the TextDirection to use when "display-hint" is set to "horizontal-buttons". Possible values include "rtl", "ltr", and "none".

The following attributes are used when constructing submenus: - "label": a user-visible string to display - "icon": icon name to display

Menu items will also show accelerators, which are usually associated with actions via set_accels_for_action, add_binding_action or add_shortcut.

CSS Nodes

PopoverMenu is just a subclass of Popover 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.

Accessibility

GtkPopoverMenu uses the MENU role, and its items use the MENU_ITEM, MENU_ITEM_CHECKBOX or MENU_ITEM_RADIO roles, depending on the action they are connected to.


Namespace: Gtk
Package: gtk4

Content:

Properties:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class Gtk.Widget
All known members inherited from interface Gtk.Native
All known members inherited from interface Gtk.ShortcutManager