Package: gtk

Class gtk:menu-button

Superclasses

Documented Subclasses

None

Direct Slots

active
The active property of type :boolean (Read / Write)
Whether the menu button is active. Since 4.10
Default value: false
always-show-arrow
The always-show-arrow property of type :boolean (Read / Write)
Whether to show a dropdown arrow even when using an icon or a custom child. Since 4.4
Default value: false
can-shrink
The can-shrink property of type :boolean (Read / Write)
Whether the size of the menu button can be made smaller than the natural size of its contents. Since 4.12
Default value: false
child
The child property of type gtk:widget (Read / Write)
The child widget. Since 4.6
direction
The direction property of type gtk:arrow-type (Read / Write)
The arrow type representing the direction in which the menu or popover will be popped out.
Default value: :down
has-frame
The has-frame property of type :boolean (Read / Write)
Whether the button has a frame.
Default value: true
icon-name
The icon-name property of type :string (Read / Write)
The name of the icon used to automatically populate the button.
Default value: nil
label
The label property of type :string (Read / Write)
The label for the button.
Default value: nil
menu-model
The menu-model property of type g:menu-model (Read / Write)
The menu model from which the popup will be created. See the gtk:menu-button-menu-model function for the interaction with the popover property.
popover
The popover property of type gtk:popover (Read / Write)
The popover that will be popped up when the button is clicked.
primary
The primary property of type :boolean (Read / Write)
Whether the menu button acts as a primary menu. Primary menus can be opened using the F10 key. Since 4.4
Default value: false
use-underline
The use-underline property of type :boolean (Read / Write)
If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
Default value: false

Details

The gtk:menu-button widget is used to display a popup when clicked on. This popup can be provided either as a gtk:popover widget or as an abstract g:menu-model object.

Figure: GtkMenuButton

The gtk:menu-button widget can show either an icon, set with the icon-name property, or a label, set with the label property. If neither is explicitly set, a gtk:image widget is automatically created, using an arrow image oriented according to the direction property or the generic "open-menu-symbolic" icon if the direction is not set.

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

For menus, the halign and 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".

CSS nodes

 menubutton
 ╰── button.toggle
     ╰── <content>
          ╰── [arrow]    
The gtk:menu-button implementation has a single CSS node with name menubutton which contains a button node with a .toggle style class.

If the menu button contains an icon, it will have the .image-button style class, if it contains text, it will have the .text-button style class. If an arrow is visible in addition to an icon, text or a custom child widget, it will also have the .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

The gtk:menu-button implementation uses the :button role of the gtk:accessible-role enumeration.

Signal Details

The "activate" signal
lambda (button)    :action      
button
The gtk:button widget which received the signal.
The signal on the gtk:menu-button widget is an action signal and emitting it causes the button to pop up its menu. Since 4.4
 

Returned by

Slot Access Functions

Inherited Slot Access Functions

See also

2024-5-4