OptionButton

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

Button control that provides selectable options when pressed.

Description

OptionButton is a type button that provides a selectable list of items when pressed. The item selected becomes the “current” item and is displayed as the button text.

Properties

ActionModeaction_modeO: 0
TextAlignalignO: 0
intselected-1
booltoggle_modeO: true

Methods

voidadd_icon_item ( Texture texture, String label, int id=-1 )
voidadd_item ( String label, int id=-1 )
voidadd_separator ( )
voidclear ( )
intget_item_count ( ) const
Textureget_item_icon ( int idx ) const
intget_item_id ( int idx ) const
intget_item_index ( int id ) const
Variantget_item_metadata ( int idx ) const
Stringget_item_text ( int idx ) const
PopupMenuget_popup ( ) const
intget_selected_id ( ) const
Variantget_selected_metadata ( ) const
boolis_item_disabled ( int idx ) const
voidremove_item ( int idx )
voidselect ( int idx )
voidset_item_disabled ( int idx, bool disabled )
voidset_item_icon ( int idx, Texture texture )
voidset_item_id ( int idx, int id )
voidset_item_metadata ( int idx, Variant metadata )
voidset_item_text ( int idx, String text )

Theme Properties

Texturearrow 
intarrow_margin2
StyleBoxdisabled 
StyleBoxfocus 
Fontfont 
Colorfont_colorColor( 0.88, 0.88, 0.88, 1 )
Colorfont_color_disabledColor( 0.9, 0.9, 0.9, 0.2 )
Colorfont_color_hoverColor( 0.94, 0.94, 0.94, 1 )
Colorfont_color_pressedColor( 1, 1, 1, 1 )
StyleBoxhover 
inthseparation2
StyleBoxnormal 
StyleBoxpressed 

Signals

  • item_focused ( int id )

Emitted the when user navigates to an item using the ui_up or ui_down actions. The index of the item selected is passed as argument.


  • item_selected ( int id )

Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.

Property Descriptions

Default-1
Getterget_selected()

The index of the currently selected item, or -1 if no item is selected.

Method Descriptions

Adds an item, with a texture icon, text label and (optionally) id. If no id is passed, the item index will be used as the item’s ID. New items are appended at the end.


Adds an item, with text label and (optionally) id. If no id is passed, the item index will be used as the item’s ID. New items are appended at the end.


  • void add_separator ( )

Adds a separator to the list of items. Separators help to group items. Separator also takes up an index and is appended at the end.


  • void clear ( )

Clears all the items in the OptionButton.


  • int get_item_count ( ) const

Returns the amount of items in the OptionButton, including separators.


Returns the icon of the item at index idx.


  • int get_item_id ( int idx ) const

Returns the ID of the item at index idx.


  • int get_item_index ( int id ) const

Returns the index of the item with the given id.


Retrieves the metadata of an item. Metadata may be any type and can be used to store extra information about an item, such as an external string ID.


Returns the text of the item at index idx.


Returns the PopupMenu contained in this button.


  • int get_selected_id ( ) const

Returns the ID of the selected item, or 0 if no item is selected.


  • Variant get_selected_metadata ( ) const

Gets the metadata of the selected item. Metadata for items can be set using set_item_metadata.


  • bool is_item_disabled ( int idx ) const

Returns true if the item at index idx is disabled.


  • void remove_item ( int idx )

Removes the item at index idx.


  • void select ( int idx )

Selects an item by index and makes it the current item. This will work even if the item is disabled.


  • void set_item_disabled ( int idx, bool disabled )

Sets whether the item at index idx is disabled.

Disabled items are drawn differently in the dropdown and are not selectable by the user. If the current selected item is set as disabled, it will remain selected.


Sets the icon of the item at index idx.


  • void set_item_id ( int idx, int id )

Sets the ID of the item at index idx.


  • void set_item_metadata ( int idx, Variant metadata )

Sets the metadata of an item. Metadata may be of any type and can be used to store extra information about an item, such as an external string ID.


Sets the text of the item at index idx.

Doc ID missing

Disclaimer: This page has been automaticaly and directly extracted from the official Godot Docs website, the 1970-01-01 at 00:00:00. It’s the English Stable version because it’s what most Godot users should use. The Copyright owners are Juan Linietsky, Ariel Manzur and the Godot community. CC-BY 3.0. Thanks for your patience and generosity.