Package: gtk

Class gtk:popover-menu

Superclasses

Documented Subclasses

None

Direct Slots

flags
The flags property of type gtk:popover-menu-flags (Read / Write)
The flags that popover uses to create/display a menu from its model. If a model is set and the flags change, contents are rebuilt, so if setting properties individually, set flags before model to avoid a redundant rebuild. Since 4.14
Default value: :sliding
menu-model
The menu-model property of type g:menu-model (Read / Write)
The model from which the menu is made.
visible-submenu
The visible-submenu property of type :string (Read / Write)
The name of the visible submenu.
Default value: nil

Details

The gtk:popover-menu class is a subclass of the gtk:popover class 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.

Figure: GtkPopoverMenu

The gtk:popover-menu widget is meant to be used primarily with menu models, using the gtk:popover-menu-new-from-model function. If you need to put other widgets such as gtk:spin-button or gtk:switch widgets into a popover, use a plain gtk:popover widget.

Menu models
The XML format understood by the gtk:builder object for the g:menu-model object 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.
<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 GNU 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 GNU 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", "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 the gtk:application-menubar function.
"custom"
a string used to match against the ID of a custom child added with the gtk:popover-menu-add-child, gtk:popover-menu-bar-add-child functions, 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 GtkTextDirection 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 the gtk:application-accels-for-action, gtk:widget-class-add-binding-action or gtk:shortcut-controller-add-shortcut functions.

CSS nodes

The gtk:popover-menu implementation is just a subclass of the gtk:popover class 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

The gtk:popover-menu implementation uses the :menu role of the gtk:accessible-role enumeration, and its items use the :menu-item, :menu-item-checkbox role or menu-item-radio roles, depending on the action they are connected to.
 

Returned by

Slot Access Functions

Inherited Slot Access Functions

See also

2024-10-26