Next: <GtkMnemonicAction>, Previous: <GtkMediaStream>, Up: Classes   [Index]


1.121 <GtkMenuButton> ¶

Class: <GtkMenuButton> ¶

It derives from <GtkWidget>.

Displays a popup when clicked.

This popup can be provided either as a <GtkPopover> or as an abstract <GMenuModel>.

The <GtkMenuButton> widget can show either an icon (set with the menu-button:icon-name property) or a label (set with the menu-button:label property). If neither is explicitly set, a <GtkImage> is automatically created, using an arrow image oriented according to menu-button:direction or the generic “open-menu-symbolic” icon if the direction is not set.

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

For menus, the widget:halign and widget:valign properties of the menu are also taken into account. For example, when the direction is down and the horizontal alignment is 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”.

| | start | center | end | | - | — | — | — | | down | ![](down-start.png) | ![](down-center.png) | ![](down-end.png) | | up | ![](up-start.png) | ![](up-center.png) | ![](up-end.png) | | left | ![](left-start.png) | ![](left-center.png) | ![](left-end.png) | | right | ![](right-start.png) | ![](right-center.png) | ![](right-end.png) |

CSS nodes ¶

menubutton
╰── button.toggle
    ╰── <content>
         ╰── [arrow]

<GtkMenuButton> has a single CSS node with name menubutton which contains a button node with a .toggle style class.

If the button contains an icon, it will have the .image-button style class, if it contains text, it will have .text-button style class. If an arrow is visible in addition to an icon, text or a custom child, it will also have .arrow-button style class.

Inside the toggle button content, there is an arrow node for the indicator, which will carry one of the .none, .up, .down, .left or .right style classes to indicate the direction that the menu will appear in. The CSS is expected to provide a suitable image for each of these cases using the -gtk-icon-source property.

Optionally, the menubutton node can carry the .circular style class to request a round appearance.

Accessibility ¶

<GtkMenuButton> uses the Gtk.AccessibleRole.button role.

Properties ¶

Property: menu-button:active self ¶

Whether the menu button is active.

Its value is a boolean.

Set it with (set! (menu-button:active self) value).

Property: menu-button:always-show-arrow self ¶

Whether to show a dropdown arrow even when using an icon or a custom child.

Its value is a boolean.

Set it with (set! (menu-button:always-show-arrow self) value).

Property: menu-button:can-shrink self ¶

Whether the size of the button can be made smaller than the natural size of its contents.

Its value is a boolean.

Set it with (set! (menu-button:can-shrink self) value).

Property: menu-button:child self ¶

The child widget.

Its value is a <GtkWidget>, or #f.

Set it with (set! (menu-button:child self) value).

Property: menu-button:direction self ¶

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

Its value is a <GtkArrowType> (or, to set it, one of its symbols).

Set it with (set! (menu-button:direction self) value).

Property: menu-button:has-frame self ¶

Whether the button has a frame.

Its value is a boolean.

Set it with (set! (menu-button:has-frame self) value).

Property: menu-button:icon-name self ¶

The name of the icon used to automatically populate the button.

Its value is a string, or #f.

Set it with (set! (menu-button:icon-name self) value).

Property: menu-button:label self ¶

The label for the button.

Its value is a string, or #f.

Set it with (set! (menu-button:label self) value).

Property: menu-button:menu-model self ¶

The <GMenuModel> from which the popup will be created.

See menu-button:set-menu-model for the interaction with the menu-button:popover property.

Its value is a <GMenuModel>, or #f.

Set it with (set! (menu-button:menu-model self) value).

Property: menu-button:popover self ¶

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

Its value is a <GtkPopover>, or #f.

Set it with (set! (menu-button:popover self) value).

Property: menu-button:primary self ¶

Whether the menu button acts as a primary menu.

Primary menus can be opened using the F10 key

Its value is a boolean.

Set it with (set! (menu-button:primary self) value).

Property: menu-button:use-underline self ¶

If set an underscore in the text indicates a mnemonic.

Its value is a boolean.

Set it with (set! (menu-button:use-underline self) value).

Procedures ¶

Method: menu-button:get-active? self ⇒ %return ¶
Method: get-active? self ⇒ %return ¶

Returns whether the menu button is active.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a boolean.

TRUE if the button is active

Method: menu-button:get-always-show-arrow? self ⇒ %return ¶
Method: get-always-show-arrow? self ⇒ %return ¶

Gets whether to show a dropdown arrow even when using an icon or a custom child.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a boolean.

whether to show a dropdown arrow even when using an icon or a custom child.

Method: menu-button:get-can-shrink? self ⇒ %return ¶
Method: get-can-shrink? self ⇒ %return ¶

Retrieves whether the button can be smaller than the natural size of its contents.

self

Passed: a <GtkMenuButton>.

a button

%return

Returned: a boolean.

true if the button can shrink, and false otherwise

Method: menu-button:get-child self ⇒ %return ¶
Method: get-child self ⇒ %return ¶

Gets the child widget of self.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a <GtkWidget>, or #f.

the child widget of self

Method: menu-button:get-direction self ⇒ %return ¶
Method: get-direction self ⇒ %return ¶

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

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a <GtkArrowType>.

a <GtkArrowType> value

Method: menu-button:get-has-frame? self ⇒ %return ¶
Method: get-has-frame? self ⇒ %return ¶

Returns whether the button has a frame.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a boolean.

#t if the button has a frame

Method: menu-button:get-icon-name self ⇒ %return ¶
Method: get-icon-name self ⇒ %return ¶

Gets the name of the icon shown in the button.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a string, or #f.

the name of the icon shown in the button

Method: menu-button:get-label self ⇒ %return ¶
Method: get-label self ⇒ %return ¶

Gets the label shown in the button

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a string, or #f.

the label shown in the button

Method: menu-button:get-menu-model self ⇒ %return ¶
Method: get-menu-model self ⇒ %return ¶

Returns the <GMenuModel> used to generate the popup.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a <GMenuModel>, or #f.

a <GMenuModel>

Method: menu-button:get-popover self ⇒ %return ¶
Method: get-popover self ⇒ %return ¶

Returns the <GtkPopover> that pops out of the button.

If the button is not using a <GtkPopover>, this function returns #f.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a <GtkPopover>, or #f.

a <GtkPopover> or #f

Method: menu-button:get-primary? self ⇒ %return ¶
Method: get-primary? self ⇒ %return ¶

Returns whether the menu button acts as a primary menu.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a boolean.

#t if the button is a primary menu

Method: menu-button:get-use-underline? self ⇒ %return ¶
Method: get-use-underline? self ⇒ %return ¶

Returns whether an embedded underline in the text indicates a mnemonic.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

%return

Returned: a boolean.

#t whether an embedded underline in the text indicates the mnemonic accelerator keys.

Procedure: menu-button:new ⇒ %return ¶

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.

%return

Returned: a <GtkWidget>.

The newly created <GtkMenuButton>

Method: menu-button:popdown self ¶
Method: popdown self ¶

Dismiss the menu.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

Method: menu-button:popup self ¶
Method: popup self ¶

Pop up the menu.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

Method: menu-button:set-active self active ¶
Method: set-active self active ¶

Sets whether the menu button is active.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

active

Passed: a boolean.

whether the menu button is active

Method: menu-button:set-always-show-arrow self always-show-arrow ¶
Method: set-always-show-arrow self always-show-arrow ¶

Sets whether to show a dropdown arrow even when using an icon or a custom child.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

always-show-arrow

Passed: a boolean.

whether to show a dropdown arrow even when using an icon or a custom child

Method: menu-button:set-can-shrink self can-shrink ¶
Method: set-can-shrink self can-shrink ¶

Sets whether the button size can be smaller than the natural size of its contents.

For text buttons, setting can-shrink to true will ellipsize the label.

For icon buttons, this function has no effect.

self

Passed: a <GtkMenuButton>.

a menu button

can-shrink

Passed: a boolean.

whether the button can shrink

Method: menu-button:set-child self [child] ¶
Method: set-child self [child] ¶

Sets the child widget of self.

Setting a child resets menu-button:label and menu-button:icon-name.

If menu-button:always-show-arrow is set to TRUE and menu-button:direction is not none, a dropdown arrow will be shown next to the child.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

child

Passed, or left out: a <GtkWidget>, or #f.

the child widget

Method: menu-button:set-create-popup-func self [func] ¶
Method: set-create-popup-func self [func] ¶

Sets func to be called when a popup is about to be shown.

func should use one of

  • menu-button:set-popover
  • menu-button:set-menu-model

to set a popup for self. If func is non-#f, self will always be sensitive.

Using this function will not reset the menu widget attached to self. Instead, this can be done manually in func.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

func

Passed, or left out: a procedure, or #f.

function to call when a popup is about to be shown, but none has been provided via other means, or #f to reset to default behavior

See GtkMenuButtonCreatePopupFunc for how it is called.

user-data

Not passed: guile-gi supplies it.

user data to pass to func

destroy-notify

Not passed: guile-gi supplies it.

destroy notify for user-data

See GDestroyNotify for how it is called.

Method: menu-button:set-direction self direction ¶
Method: set-direction self direction ¶

Sets the direction in which the popup will be popped up.

If the button is automatically populated with an arrow icon, its direction will be changed to match.

If the does not fit in the available space in the given direction, GTK will its best to keep it inside the screen and fully visible.

If you pass none for a direction, the popup will behave as if you passed down (although you won’t see any arrows).

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

direction

Passed: a <GtkArrowType>, or one of its symbols.

a <GtkArrowType>

Method: menu-button:set-has-frame self has-frame ¶
Method: set-has-frame self has-frame ¶

Sets the style of the button.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

has-frame

Passed: a boolean.

whether the button should have a visible frame

Method: menu-button:set-icon-name self icon-name ¶
Method: set-icon-name self icon-name ¶

Sets the name of an icon to show inside the menu button.

Setting icon name resets menu-button:label and menu-button:child.

If menu-button:always-show-arrow is set to TRUE and menu-button:direction is not none, a dropdown arrow will be shown next to the icon.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

icon-name

Passed: a string.

the icon name

Method: menu-button:set-label self label ¶
Method: set-label self label ¶

Sets the label to show inside the menu button.

Setting a label resets menu-button:icon-name and menu-button:child.

If menu-button:direction is not none, a dropdown arrow will be shown next to the label.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

label

Passed: a string.

the label

Method: menu-button:set-menu-model self [menu-model] ¶
Method: set-menu-model self [menu-model] ¶

Sets the <GMenuModel> from which the popup will be constructed.

If menu-model is #f, the button is disabled.

A <GtkPopover> will be created from the menu model with popover-menu:new-from-model. Actions will be connected as documented for this function.

If menu-button:popover is already set, it will be dissociated from the self, and the property is set to #f.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

menu-model

Passed, or left out: a <GMenuModel>, or #f.

a <GMenuModel>, or #f to unset and disable the button

Method: menu-button:set-popover self [popover] ¶
Method: set-popover self [popover] ¶

Sets the <GtkPopover> that will be popped up when the self is clicked.

If popover is #f, the button is disabled.

If menu-button:menu-model is set, the menu model is dissociated from the self, and the property is set to #f.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

popover

Passed, or left out: a <GtkPopover>, or #f.

a <GtkPopover>, or #f to unset and disable the button

Method: menu-button:set-primary self primary ¶
Method: set-primary self primary ¶

Sets whether menu button acts as a primary menu.

Primary menus can be opened with the F10 key.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

primary

Passed: a boolean.

whether the menubutton should act as a primary menu

Method: menu-button:set-use-underline self use-underline ¶
Method: set-use-underline self use-underline ¶

If true, an underline in the text indicates a mnemonic.

self

Passed: a <GtkMenuButton>.

a <GtkMenuButton>

use-underline

Passed: a boolean.

#t if underlines in the text indicate mnemonics

Signals ¶

Signal: menu-button:activate ¶

Connect a handler with (connect object menu-button:activate handler). It is called as (handler self).

Emitted to when the menu button is activated.

The ::activate signal on <GtkMenuButton> is an action signal and emitting it causes the button to pop up its menu.

self

Passed: a <GtkMenuButton>.


Next: <GtkMnemonicAction>, Previous: <GtkMediaStream>, Up: Classes   [Index]