Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

OptionButton

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

A button that brings up a dropdown with selectable options when pressed.

Description

OptionButton is a type of button that brings up a dropdown with selectable items when pressed. The item selected becomes the "current" item and is displayed as the button text.

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

Note: The ID values used for items are limited to 32 bits, not full 64 bits of int. This has a range of -2^32 to 2^32 - 1, i.e. -2147483648 to 2147483647.

Note: The Button.text and Button.icon properties are set automatically based on the selected item. They shouldn't be changed manually.

Properties

ActionMode

action_mode

0 (overrides BaseButton)

HorizontalAlignment

alignment

0 (overrides Button)

bool

allow_reselect

false

bool

fit_to_longest_item

true

int

item_count

0

int

selected

-1

bool

toggle_mode

true (overrides BaseButton)

Methods

void

add_icon_item(texture: Texture2D, label: String, id: int = -1)

void

add_item(label: String, id: int = -1)

void

add_separator(text: String = "")

void

clear()

Texture2D

get_item_icon(idx: int) const

int

get_item_id(idx: int) const

int

get_item_index(id: int) const

Variant

get_item_metadata(idx: int) const

String

get_item_text(idx: int) const

String

get_item_tooltip(idx: int) const

PopupMenu

get_popup() const

int

get_selectable_item(from_last: bool = false) const

int

get_selected_id() const

Variant

get_selected_metadata() const

bool

has_selectable_items() const

bool

is_item_disabled(idx: int) const

bool

is_item_separator(idx: int) const

void

remove_item(idx: int)

void

select(idx: int)

void

set_disable_shortcuts(disabled: bool)

void

set_item_disabled(idx: int, disabled: bool)

void

set_item_icon(idx: int, texture: Texture2D)

void

set_item_id(idx: int, id: int)

void

set_item_metadata(idx: int, metadata: Variant)

void

s