Class

GtkMenuButton

[]

Description [src]

class Gtk.MenuButton : Gtk.ToggleButton
  implements Atk.ImplementorIface, Gtk.Actionable, Gtk.Activatable, Gtk.Buildable {
  /* No available fields */
}

The GtkMenuButton widget is used to display a popup when clicked on. This popup can be provided either as a GtkMenu, a GtkPopover or an abstract GMenuModel.

The GtkMenuButton widget can hold any valid child widget. That is, it can hold almost any other standard GtkWidget. The most commonly used child is GtkImage. If no widget is explicitely added to the GtkMenuButton, a GtkImage is automatically created, using an arrow image oriented according to GtkMenuButton:direction or the generic “open-menu-symbolic” icon if the direction is not set.

The positioning of the popup is determined by the GtkMenuButton:direction property of the menu button.

For menus, the GtkWidget:halign and GtkWidget:valign properties of the menu are also taken into account. For example, when the direction is GTK_ARROW_DOWN and the horizontal alignment is GTK_ALIGN_START, the menu will be positioned below the button, with the starting edge (depending on the text direction) of the menu aligned with the starting edge of the button. If there is not enough space below the button, the menu is popped up above the button instead. If the alignment would move part of the menu offscreen, it is “pushed in”.

Direction = Down

  • halign = start

  • halign = center

  • halign = end

Direction = Up

  • halign = start

  • halign = center

  • halign = end

Direction = Left

  • valign = start

  • valign = center

  • valign = end

Direction = Right

  • valign = start

  • valign = center

  • valign = end

CSS nodes

GtkMenuButton has a single CSS node with name button. To differentiate it from a plain GtkButton, it gets the .popup style class.

[]

Hierarchy

hierarchy this GtkMenuButton implements_0 AtkImplementorIface this--implements_0 implements_1 GtkActionable this--implements_1 implements_2 GtkActivatable this--implements_2 implements_3 GtkBuildable this--implements_3 ancestor_0 GtkToggleButton ancestor_0--this ancestor_1 GtkButton ancestor_1--ancestor_0 ancestor_2 GtkBin ancestor_2--ancestor_1 ancestor_3 GtkContainer ancestor_3--ancestor_2 ancestor_4 GtkWidget ancestor_4--ancestor_3 ancestor_5 GInitiallyUnowned ancestor_5--ancestor_4 ancestor_6 GObject ancestor_6--ancestor_5
[]

Constructors

gtk_menu_button_new

Creates a new GtkMenuButton widget with downwards-pointing arrow as the only child. You can replace the child widget with another GtkWidget should you wish to.

since: 3.6

[]

Instance methods

gtk_menu_button_get_align_widget

Returns the parent GtkWidget to use to line up with menu.

since: 3.6

gtk_menu_button_get_direction

Returns the direction the popup will be pointing at when popped up.

since: 3.6

gtk_menu_button_get_menu_model

Returns the GMenuModel used to generate the popup.

since: 3.6

gtk_menu_button_get_popover

Returns the GtkPopover that pops out of the button. If the button is not using a GtkPopover, this function returns NULL.

since: 3.12

gtk_menu_button_get_popup

Returns the GtkMenu that pops out of the button. If the button does not use a GtkMenu, this function returns NULL.

since: 3.6

gtk_menu_button_get_use_popover

Returns whether a GtkPopover or a GtkMenu will be constructed from the menu model.

since: 3.12

gtk_menu_button_set_align_widget

Sets the GtkWidget to use to line the menu with when popped up. Note that the align_widget must contain the GtkMenuButton itself.

since: 3.6

gtk_menu_button_set_direction

Sets the direction in which the popup will be popped up, as well as changing the arrow’s direction. The child will not be changed to an arrow if it was customized.

since: 3.6

gtk_menu_button_set_menu_model

Sets the GMenuModel from which the popup will be constructed, or NULL to dissociate any existing menu model and disable the button.

since: 3.6

gtk_menu_button_set_popover

Sets the GtkPopover that will be popped up when the menu_button is clicked, or NULL to dissociate any existing popover and disable the button.

since: 3.12

gtk_menu_button_set_popup

Sets the GtkMenu that will be popped up when the menu_button is clicked, or NULL to dissociate any existing menu and disable the button.

since: 3.6

gtk_menu_button_set_use_popover

Sets whether to construct a GtkPopover instead of GtkMenu when gtk_menu_button_set_menu_model() is called. Note that this property is only consulted when a new menu model is set.

since: 3.12

Methods inherited from GtkToggleButton (7)
Methods inherited from GtkButton (24)
Methods inherited from GtkBin (1)
Methods inherited from GtkContainer (33)
Methods inherited from GtkWidget (263)
Methods inherited from GObject (43)
Methods inherited from GtkActionable (6)
Methods inherited from GtkActivatable (6)
Methods inherited from GtkBuildable (10)
[]

Properties

Gtk.MenuButton:align-widget

The GtkWidget to use to align the menu with.

since: 3.6

Gtk.MenuButton:direction

The GtkArrowType representing the direction in which the menu or popover will be popped out.

since: 3.6

Gtk.MenuButton:menu-model

The GMenuModel from which the popup will be created. Depending on the GtkMenuButton:use-popover property, that may be a menu or a popover.

since: 3.6

Gtk.MenuButton:popover

The GtkPopover that will be popped up when the button is clicked.

since: 3.12

Gtk.MenuButton:popup

The GtkMenu that will be popped up when the button is clicked.

since: 3.6

Gtk.MenuButton:use-popover

Whether to construct a GtkPopover from the menu model, or a GtkMenu.

since: 3.12

Properties inherited from GtkToggleButton (3)
Properties inherited from GtkButton (9)
Properties inherited from GtkContainer (3)
Properties inherited from GtkWidget (39)
Properties inherited from GtkActionable (2)
Properties inherited from GtkActivatable (2)
[]

Signals

Signals inherited from GtkToggleButton (1)
Signals inherited from GtkButton (6)
Signals inherited from GtkContainer (4)
Signals inherited from GtkWidget (69)
Signals inherited from GObject (1)

Class structure