Class: Gtk::MenuButton
- Defined in:
- (unknown)
Overview
The GtkMenuButton widget is used to display 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
[propertyGtk.MenuButton:icon-name] property) or a label (set with the
[propertyGtk.MenuButton:label] property). If neither is explicitly set,
a [classGtk.Image] is automatically created, using an arrow image oriented
according to [propertyGtk.MenuButton:direction] or the generic
“open-menu-symbolic” icon if the direction is not set.
The positioning of the popup is determined by the [propertyGtk.MenuButton:direction] property of the menu button.
For menus, the [propertyGtk.Widget:halign] and [propertyGtk.Widget: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”.
| start | center | end | |
|---|---|---|---|
| down | ![]() |
![]() |
![]() |
| up | ![]() |
![]() |
![]() |
| left | ![]() |
![]() |
![]() |
| right | ![]() |
![]() |
![]() |
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_ACCESSIBLE_ROLE_BUTTON role.
Instance Method Summary collapse
-
#active ⇒ Boolean
Returns whether the menu button is active.
-
#active=(active) ⇒ Boolean
Whether the menu button is active.
-
#active? ⇒ Boolean
Whether the menu button is active.
-
#always_show_arrow ⇒ Boolean
Gets whether to show a dropdown arrow even when using an icon or a custom child.
-
#always_show_arrow=(always_show_arrow) ⇒ Boolean
Whether to show a dropdown arrow even when using an icon or a custom child.
-
#always_show_arrow? ⇒ Boolean
Whether to show a dropdown arrow even when using an icon or a custom child.
-
#can_shrink ⇒ Boolean
Retrieves whether the button can be smaller than the natural size of its contents.
-
#can_shrink=(can_shrink) ⇒ Boolean
Whether the size of the button can be made smaller than the natural size of its contents.
-
#can_shrink? ⇒ Boolean
Whether the size of the button can be made smaller than the natural size of its contents.
-
#child ⇒ Gtk::Widget
The child widget.
-
#child=(child) ⇒ Gtk::Widget
The child widget.
-
#direction ⇒ Gtk::ArrowType
The
GtkArrowTyperepresenting the direction in which the menu or popover will be popped out. -
#direction=(direction) ⇒ Gtk::ArrowType
The
GtkArrowTyperepresenting the direction in which the menu or popover will be popped out. -
#has_frame ⇒ Boolean
Returns whether the button has a frame.
-
#has_frame=(has_frame) ⇒ Boolean
Whether the button has a frame.
-
#has_frame? ⇒ Boolean
Whether the button has a frame.
-
#icon_name ⇒ String
The name of the icon used to automatically populate the button.
-
#icon_name=(icon_name) ⇒ String
The name of the icon used to automatically populate the button.
-
#initialize ⇒ Gtk::Widget
constructor
Creates a new
GtkMenuButtonwidget with downwards-pointing arrow as the only child. -
#label ⇒ String
The label for the button.
-
#label=(label) ⇒ String
The label for the button.
-
#menu_model ⇒ Gio::MenuModel
The
GMenuModelfrom which the popup will be created. -
#menu_model=(menu_model) ⇒ Gio::MenuModel
The
GMenuModelfrom which the popup will be created. -
#popdown ⇒ nil
Dismiss the menu.
-
#popover ⇒ Gtk::Popover
The
GtkPopoverthat will be popped up when the button is clicked. -
#popover=(popover) ⇒ Gtk::Popover
The
GtkPopoverthat will be popped up when the button is clicked. -
#popup ⇒ nil
Pop up the menu.
-
#primary ⇒ Boolean
Returns whether the menu button acts as a primary menu.
-
#primary=(primary) ⇒ Boolean
Whether the menu button acts as a primary menu.
-
#primary? ⇒ Boolean
Whether the menu button acts as a primary menu.
-
#set_create_popup_func(func, user_data, destroy_notify) ⇒ nil
Sets func to be called when a popup is about to be shown.
-
#use_underline ⇒ Boolean
Returns whether an embedded underline in the text indicates a mnemonic.
-
#use_underline=(use_underline) ⇒ Boolean
If set an underscore in the text indicates a mnemonic.
-
#use_underline? ⇒ Boolean
If set an underscore in the text indicates a mnemonic.
Methods inherited from Widget
#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_events, #add_events_raw, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #display, #dispose_template, #drag_check_threshold, #drag_dest_set, #drag_dest_set_raw, #drag_source_set, #drag_source_set_raw, #error_bell, #events, #events_raw, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, have_template?, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_action_group_raw, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #render_icon_pixbuf, #render_icon_pixbuf_raw, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_allocation, set_connect_func, set_connect_func_raw, #set_events, #set_events_raw, #set_size_request, #set_size_request_raw, #set_state_flags, #set_template, #set_template_raw, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #style_context_raw, #style_get_property, #style_get_property_raw, #template=, template_children, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #translate_coordinates_raw, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=
Constructor Details
#initialize ⇒ Gtk::Widget
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.
Instance Method Details
#active ⇒ Boolean
Returns whether the menu button is active.
#active=(active) ⇒ Boolean
Whether the menu button is active.
#active? ⇒ Boolean
Whether the menu button is active.
#always_show_arrow ⇒ Boolean
Gets whether to show a dropdown arrow even when using an icon or a custom child. child.
#always_show_arrow=(always_show_arrow) ⇒ Boolean
Whether to show a dropdown arrow even when using an icon or a custom child.
#always_show_arrow? ⇒ Boolean
Whether to show a dropdown arrow even when using an icon or a custom child.
#can_shrink ⇒ Boolean
Retrieves whether the button can be smaller than the natural size of its contents.
#can_shrink=(can_shrink) ⇒ Boolean
Whether the size of the button can be made smaller than the natural size of its contents.
#can_shrink? ⇒ Boolean
Whether the size of the button can be made smaller than the natural size of its contents.
#child ⇒ Gtk::Widget
The child widget.
#child=(child) ⇒ Gtk::Widget
The child widget.
#direction ⇒ Gtk::ArrowType
The GtkArrowType representing the direction in which the
menu or popover will be popped out.
#direction=(direction) ⇒ Gtk::ArrowType
The GtkArrowType representing the direction in which the
menu or popover will be popped out.
#has_frame ⇒ Boolean
Returns whether the button has a frame.
#has_frame=(has_frame) ⇒ Boolean
Whether the button has a frame.
#has_frame? ⇒ Boolean
Whether the button has a frame.
#icon_name ⇒ String
The name of the icon used to automatically populate the button.
#icon_name=(icon_name) ⇒ String
The name of the icon used to automatically populate the button.
#label ⇒ String
The label for the button.
#label=(label) ⇒ String
The label for the button.
#menu_model ⇒ Gio::MenuModel
The GMenuModel from which the popup will be created.
See [methodGtk.MenuButton.set_menu_model] for the interaction with the [propertyGtk.MenuButton:popover] property.
#menu_model=(menu_model) ⇒ Gio::MenuModel
The GMenuModel from which the popup will be created.
See [methodGtk.MenuButton.set_menu_model] for the interaction with the [propertyGtk.MenuButton:popover] property.
#popdown ⇒ nil
Dismiss the menu.
#popover ⇒ Gtk::Popover
The GtkPopover that will be popped up when the button is clicked.
#popover=(popover) ⇒ Gtk::Popover
The GtkPopover that will be popped up when the button is clicked.
#popup ⇒ nil
Pop up the menu.
#primary ⇒ Boolean
Returns whether the menu button acts as a primary menu.
#primary=(primary) ⇒ Boolean
Whether the menu button acts as a primary menu.
Primary menus can be opened using the F10 key
#primary? ⇒ Boolean
Whether the menu button acts as a primary menu.
Primary menus can be opened using the F10 key
#set_create_popup_func(func, user_data, destroy_notify) ⇒ nil
Sets func to be called when a popup is about to be shown.
func should use one of
- [methodGtk.MenuButton.set_popover]
- [methodGtk.MenuButton.set_menu_model]
to set a popup for menu_button. If func is non-nil, menu_button will always be sensitive.
Using this function will not reset the menu widget attached to menu_button. Instead, this can be done manually in func.
#use_underline ⇒ Boolean
Returns whether an embedded underline in the text indicates a mnemonic.
#use_underline=(use_underline) ⇒ Boolean
If set an underscore in the text indicates a mnemonic.
#use_underline? ⇒ Boolean
If set an underscore in the text indicates a mnemonic.











