Up to date

This page is up to date for Godot 4.0. If you still find outdated information, please open an issue.

MenuButton

Inherits: Button < BaseButton < Control < CanvasItem < Node < Object

A button that brings up a PopupMenu when clicked.

Description

A button that brings up a PopupMenu when clicked. To create new items inside this PopupMenu, use get_popup().add_item("My Item Name"). You can also create them directly from Godot editor’s inspector.

See also BaseButton which contains common properties and methods associated with this node.

Properties

ActionMode

action_mode

0 (overrides BaseButton)

bool

flat

true (overrides Button)

FocusMode

focus_mode

0 (overrides Control)

int

item_count

0

bool

switch_on_hover

false

bool

toggle_mode

true (overrides BaseButton)

Methods

PopupMenu

get_popup ( ) const

void

set_disable_shortcuts ( bool disabled )

void

show_popup ( )

Theme Properties

Color

font_color

Color(0.875, 0.875, 0.875, 1)

Color

font_disabled_color

Color(1, 1, 1, 0.3)

Color

font_focus_color

Color(0.95, 0.95, 0.95, 1)

Color

font_hover_color

Color(0.95, 0.95, 0.95, 1)

Color

font_outline_color

Color(1, 1, 1, 1)

Color

font_pressed_color

Color(1, 1, 1, 1)

int

h_separation

3

int

outline_size

0

Font

font

int

font_size

StyleBox

disabled

StyleBox

focus

StyleBox

hover

StyleBox

normal

StyleBox

pressed


Signals

about_to_popup ( )

Emitted when the PopupMenu of this MenuButton is about to show.


Property Descriptions

int item_count = 0

  • void set_item_count ( int value )

  • int get_item_count ( )

The number of items currently in the list.


bool switch_on_hover = false

  • void set_switch_on_hover ( bool value )

  • bool is_switch_on_hover ( )

If true, when the cursor hovers above another MenuButton within the same parent which also has switch_on_hover enabled, it will close the current MenuButton and open the other one.


Method Descriptions

PopupMenu get_popup ( ) const

Returns the PopupMenu contained in this button.

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their Window.visible property.


void set_disable_shortcuts ( bool disabled )

If true, shortcuts are disabled and cannot be used to trigger the button.


void show_popup ( )

Adjusts popup position and sizing for the MenuButton, then shows the PopupMenu. Prefer this over using get_popup().popup().


Theme Property Descriptions

Color font_color = Color(0.875, 0.875, 0.875, 1)

Default text Color of the MenuButton.


Color font_disabled_color = Color(1, 1, 1, 0.3)

Text Color used when the MenuButton is disabled.


Color font_focus_color = Color(0.95, 0.95, 0.95, 1)

Text Color used when the MenuButton is focused. Only replaces the normal text color of the button. Disabled, hovered, and pressed states take precedence over this color.


Color font_hover_color = Color(0.95, 0.95, 0.95, 1)

Text Color used when the MenuButton is being hovered.


Color font_outline_color = Color(1, 1, 1, 1)

The tint of text outline of the MenuButton.


Color font_pressed_color = Color(1, 1, 1, 1)

Text Color used when the MenuButton is being pressed.


int h_separation = 3

The horizontal space between MenuButton‘s icon and text. Negative values will be treated as 0 when used.


int outline_size = 0

The size of the text outline.

Note: If using a font with FontFile.multichannel_signed_distance_field enabled, its FontFile.msdf_pixel_range must be set to at least twice the value of outline_size for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.


Font font

Font of the MenuButton‘s text.


int font_size

Font size of the MenuButton‘s text.


StyleBox disabled

StyleBox used when the MenuButton is disabled.


StyleBox focus

StyleBox used when the MenuButton is focused. The focus StyleBox is displayed over the base StyleBox, so a partially transparent StyleBox should be used to ensure the base StyleBox remains visible. A StyleBox that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a StyleBoxEmpty resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.


StyleBox hover

StyleBox used when the MenuButton is being hovered.


StyleBox normal

Default StyleBox for the MenuButton.


StyleBox pressed

StyleBox used when the MenuButton is being pressed.