Inheritance #
- AudioServer
- CameraServer
- ClassDB
- DisplayServer
- EditorFileSystemDirectory
- EditorInterface
- EditorPaths
- EditorSelection
- EditorUndoRedoManager
- EditorVCSInterface
- Engine
- EngineDebugger
- FramebufferCacheRD
- GDExtensionManager
- Geometry2D
- Geometry3D
- IP
- Input
- InputMap
- JNISingleton
- JSONRPC
- JavaClassWrapper
- JavaScriptBridge
- MainLoop (1)
- Marshalls
- MovieWriter
- NativeMenu
- NavigationMeshGenerator
- NavigationServer2D
- NavigationServer3D
- Node (21)
- OS
- OpenXRExtensionWrapperExtension
- OpenXRInteractionProfileMetadata
- Performance
- PhysicsDirectBodyState2D (1)
- PhysicsDirectBodyState3D (1)
- PhysicsDirectSpaceState2D (1)
- PhysicsDirectSpaceState3D (1)
- PhysicsServer2D (1)
- PhysicsServer2DManager
- PhysicsServer3D (1)
- PhysicsServer3DManager
- PhysicsServer3DRendering
ServerHandler
- ProjectSettings
- RefCounted (121)
- RenderData (2)
- RenderSceneData (2)
- RenderingDevice
- RenderingServer
- ResourceLoader
- ResourceSaver
- ResourceUID
- ScriptLanguage (1)
- ShaderIncludeDB
- TextServerManager
- ThemeDB
- TileData
- Time
- TranslationServer
- TreeItem
- UndoRedo
- UniformSetCacheRD
- WorkerThreadPool
- XRServer
- XRVRS
- AnimationMixer (2)
- AudioStreamPlayer
- CanvasItem (2)
- CanvasLayer (1)
- EditorFileSystem
- EditorPlugin (1)
- EditorResourcePreview
- HTTPRequest
- InstancePlaceholder
- MissingNode
- MultiplayerSpawner
- MultiplayerSynchronizer
- NavigationAgent2D
- NavigationAgent3D
- Node3D (31)
- ResourcePreloader
- ShaderGlobalsOverride
- StatusIndicator
- Timer
- Viewport (2)
- WorldEnvironment
- BaseButton (3)
- ColorRect
- Container (13)
- GraphEdit
- ItemList
- Label
- LineEdit
- MenuBar
- NinePatchRect
- Panel
- Range (6)
- ReferenceRect
- RichTextLabel
- Separator (2)
- TabBar
- TextEdit (1)
- TextureRect
- Tree
- VideoStreamPlayer
Table of contents
-
var action_mode = ACTION_MODE_BUTTON_PRESS -
var alignment: int = 0 -
var allow_reselect: bool = false -
var fit_to_longest_item: bool = true -
var item_count: int = 0 -
var selected: int = -1 -
var toggle_mode: bool = true -
func add_icon_item(id: int = -1) -> void -
func add_item(id: int = -1) -> void -
func add_separator(text: String = "") -> void -
func clear() -> void -
const func get_item_icon(idx: int) -> Texture2D -
const func get_item_id(idx: int) -> int -
const func get_item_index(id: int) -> int -
const func get_item_metadata(idx: int) -> Variant -
const func get_item_text(idx: int) -> String -
const func get_item_tooltip(idx: int) -> String -
const func get_popup() -> PopupMenu -
const func get_selectable_item(from_last: bool = false) -> int -
const func get_selected_id() -> int -
const func get_selected_metadata() -> Variant -
const func has_selectable_items() -> bool -
const func is_item_disabled(idx: int) -> bool -
const func is_item_separator(idx: int) -> bool -
func remove_item(idx: int) -> void -
func select(idx: int) -> void -
func set_disable_shortcuts(disabled: bool) -> void -
func set_item_disabled(disabled: bool) -> void -
func set_item_icon(texture: Texture2D) -> void -
func set_item_id(id: int) -> void -
func set_item_metadata(metadata: Variant) -> void -
func set_item_text(text: String) -> void -
func set_item_tooltip(tooltip: String) -> void -
func show_popup() -> void -
signal item_focused(index: int) -
signal item_selected(index: int) -
self["theme_override_constants/arrow_margin"] = 4 as int -
self["theme_override_constants/modulate_arrow"] = 0 as int -
self["theme_override_icons/arrow"] = icon as Texture2D
OptionButton #
is_instantiable, Node, core, not_builtin_classes
A button that brings up a dropdown with selectable options when pressed.
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.
Members #
var action_mode = ACTION_MODE_BUTTON_PRESS#
var alignment: int = 0#
var allow_reselect: bool = false#
If true, the currently selected item can be selected again.
var fit_to_longest_item: bool = true#
If true, minimum size will be determined by the longest item's text, instead of the currently selected one's.
Note: For performance reasons, the minimum size doesn't update immediately when adding, removing or modifying items.
var item_count: int = 0#
The number of items to select from.
var selected: int = -1#
The index of the currently selected item, or -1 if no item is selected.
var toggle_mode: bool = true#
Methods #
func add_icon_item(id: int = -1) -> void#
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.
func add_item(id: int = -1) -> void#
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.
func add_separator(text: String = "") -> void#
Adds a separator to the list of items. Separators help to group items, and can optionally be given a text header. A separator also gets an index assigned, and is appended at the end of the item list.
func clear() -> void#
Clears all the items in the OptionButton.
const func get_item_icon(idx: int) -> Texture2D#
Returns the icon of the item at index idx.
const func get_item_id(idx: int) -> int#
Returns the ID of the item at index idx.
const func get_item_index(id: int) -> int#
Returns the index of the item with the given id.
const func get_item_metadata(idx: int) -> Variant#
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.
const func get_item_text(idx: int) -> String#
Returns the text of the item at index idx.
const func get_item_tooltip(idx: int) -> String#
Returns the tooltip of the item at index idx.
const func get_popup() -> PopupMenu#
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.
const func get_selectable_item(from_last: bool = false) -> int#
Returns the index of the first item which is not disabled, or marked as a separator. If from_last is true, the items will be searched in reverse order.
Returns -1 if no item is found.
const func get_selected_id() -> int#
Returns the ID of the selected item, or -1 if no item is selected.
const func get_selected_metadata() -> Variant#
Gets the metadata of the selected item. Metadata for items can be set using set_item_metadata.
const func has_selectable_items() -> bool#
Returns true if this button contains at least one item which is not disabled, or marked as a separator.
const func is_item_disabled(idx: int) -> bool#
Returns true if the item at index idx is disabled.
const func is_item_separator(idx: int) -> bool#
Returns true if the item at index idx is marked as a separator.
func remove_item(idx: int) -> void#
Removes the item at index idx.
func select(idx: int) -> void#
Selects an item by index and makes it the current item. This will work even if the item is disabled.
Passing -1 as the index deselects any currently selected item.
func set_disable_shortcuts(disabled: bool) -> void#
If true, shortcuts are disabled and cannot be used to trigger the button.
func set_item_disabled(disabled: bool) -> void#
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.
func set_item_icon(texture: Texture2D) -> void#
Sets the icon of the item at index idx.
func set_item_id(id: int) -> void#
Sets the ID of the item at index idx.
func set_item_metadata(metadata: Variant) -> void#
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.
func set_item_text(text: String) -> void#
Sets the text of the item at index idx.
func set_item_tooltip(tooltip: String) -> void#
Sets the tooltip of the item at index idx.
func show_popup() -> void#
Adjusts popup position and sizing for the OptionButton, then shows the PopupMenu. Prefer this over using get_popup().popup().
Annotations #
Constants #
Constructors #
Enums #
Operators #
Signals #
signal item_focused(index: int)#
Emitted when the user navigates to an item using the ProjectSettings.input/ui_up or ProjectSettings.input/ui_down input actions. The index of the item selected is passed as argument.
signal item_selected(index: int)#
Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
allow_reselect must be enabled to reselect an item.
Theme Items #
self["theme_override_constants/arrow_margin"] = 4 as int#
The horizontal space between the arrow icon and the right edge of the button.
self["theme_override_constants/modulate_arrow"] = 0 as int#
If different than 0, the arrow icon will be modulated to the font color.
self["theme_override_icons/arrow"] = icon as Texture2D#
The arrow icon to be drawn on the right end of the button.