PopoverMenu

class PopoverMenu(**properties: Any)

Superclasses: Popover, Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget, Native, ShortcutManager

GtkPopoverMenu is a subclass of GtkPopover that implements menu behavior.

https://docs.gtk.org/gtk4/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. The property flags controls this appearance.

GtkPopoverMenu is meant to be used primarily with menu models, using new_from_model. If you need to put other widgets such as a GtkSpinButton or a GtkSwitch into a popover, you can use add_child.

For more dialog-like behavior, use a plain GtkPopover.

CSS Nodes

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 main popover node.

Menu items have nodes with name button and class .model. If a section display-hint is set, the section gets a node box with class horizontal plus a class with the same text as the display hint. Note that said box may not be the direct ancestor of the item button’s. Thus, for example, to style items in an inline-buttons section, select inline-buttons button.model. Other things that may be of interest to style in menus include label nodes.

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.

Constructors

class PopoverMenu
classmethod new_from_model(model: MenuModel | None = None) Widget

Creates a GtkPopoverMenu and populates it according to model.

The created buttons are connected to actions found in the GtkApplicationWindow to which the popover belongs - typically by means of being attached to a widget that is contained within the GtkApplicationWindow’s widget hierarchy.

Actions can also be added using insert_action_group on the menus attach widget or on any of its parent widgets.

This function creates menus with sliding submenus. See new_from_model_full for a way to control this.

Parameters:

model – a GMenuModel

classmethod new_from_model_full(model: MenuModel, flags: PopoverMenuFlags) Widget

Creates a GtkPopoverMenu and populates it according to model.

The created buttons are connected to actions found in the action groups that are accessible from the parent widget. This includes the GtkApplicationWindow to which the popover belongs. Actions can also be added using insert_action_group on the parent widget or on any of its parent widgets.

Parameters:
  • model – a GMenuModel

  • flags – flags that affect how the menu is created

Methods

class PopoverMenu
add_child(child: Widget, id: str) bool

Adds a custom widget to a generated menu.

For this to work, the menu model of popover must have an item with a custom attribute that matches id.

Parameters:
  • child – the GtkWidget to add

  • id – the ID to insert child at

get_flags() PopoverMenuFlags

Returns the flags that popover uses to create/display a menu from its model.

Added in version 4.14.

get_menu_model() MenuModel | None

Returns the menu model used to populate the popover.

remove_child(child: Widget) bool

Removes a widget that has previously been added with add_child()

Parameters:

child – the GtkWidget to remove

set_flags(flags: PopoverMenuFlags) None

Sets 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.

Added in version 4.14.

Parameters:

flags – a set of GtkPopoverMenuFlags

set_menu_model(model: MenuModel | None = None) None

Sets a new menu model on popover.

The existing contents of popover are removed, and the popover is populated with new contents according to model.

Parameters:

model – a GMenuModel

Properties

class PopoverMenu
props.flags: PopoverMenuFlags

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.

Added in version 4.14.

props.menu_model: MenuModel

The model from which the menu is made.

props.visible_submenu: str

The name of the visible submenu.