:github_url: hide .. Generated automatically by doc/tools/makerst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the OptionButton.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_OptionButton: OptionButton ============ **Inherits:** :ref:`Button` **<** :ref:`BaseButton` **<** :ref:`Control` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`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 ---------- +-----------------------------------------------+-------------------------------------------------------+------------------------------+ | :ref:`ActionMode` | action_mode | ``0`` *(parent override)* | +-----------------------------------------------+-------------------------------------------------------+------------------------------+ | :ref:`TextAlign` | align | ``0`` *(parent override)* | +-----------------------------------------------+-------------------------------------------------------+------------------------------+ | :ref:`int` | :ref:`selected` | ``-1`` | +-----------------------------------------------+-------------------------------------------------------+------------------------------+ | :ref:`bool` | toggle_mode | ``true`` *(parent override)* | +-----------------------------------------------+-------------------------------------------------------+------------------------------+ Methods ------- +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_icon_item` **(** :ref:`Texture` texture, :ref:`String` label, :ref:`int` id=-1 **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_item` **(** :ref:`String` label, :ref:`int` id=-1 **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_separator` **(** **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear` **(** **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_item_count` **(** **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Texture` | :ref:`get_item_icon` **(** :ref:`int` idx **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_item_id` **(** :ref:`int` idx **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_item_index` **(** :ref:`int` id **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_item_metadata` **(** :ref:`int` idx **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_item_text` **(** :ref:`int` idx **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PopupMenu` | :ref:`get_popup` **(** **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_selected_id` **(** **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_selected_metadata` **(** **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_item_disabled` **(** :ref:`int` idx **)** |const| | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`remove_item` **(** :ref:`int` idx **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`select` **(** :ref:`int` idx **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_item_disabled` **(** :ref:`int` idx, :ref:`bool` disabled **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_item_icon` **(** :ref:`int` idx, :ref:`Texture` texture **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_item_id` **(** :ref:`int` idx, :ref:`int` id **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_item_metadata` **(** :ref:`int` idx, :ref:`Variant` metadata **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_item_text` **(** :ref:`int` idx, :ref:`String` text **)** | +-----------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Theme Properties ---------------- +---------------------------------+---------------------+------------------------------+ | :ref:`Texture` | arrow | | +---------------------------------+---------------------+------------------------------+ | :ref:`int` | arrow_margin | 2 | +---------------------------------+---------------------+------------------------------+ | :ref:`StyleBox` | disabled | | +---------------------------------+---------------------+------------------------------+ | :ref:`StyleBox` | focus | | +---------------------------------+---------------------+------------------------------+ | :ref:`Font` | font | | +---------------------------------+---------------------+------------------------------+ | :ref:`Color` | font_color | Color( 0.88, 0.88, 0.88, 1 ) | +---------------------------------+---------------------+------------------------------+ | :ref:`Color` | font_color_disabled | Color( 0.9, 0.9, 0.9, 0.2 ) | +---------------------------------+---------------------+------------------------------+ | :ref:`Color` | font_color_hover | Color( 0.94, 0.94, 0.94, 1 ) | +---------------------------------+---------------------+------------------------------+ | :ref:`Color` | font_color_pressed | Color( 1, 1, 1, 1 ) | +---------------------------------+---------------------+------------------------------+ | :ref:`StyleBox` | hover | | +---------------------------------+---------------------+------------------------------+ | :ref:`int` | hseparation | 2 | +---------------------------------+---------------------+------------------------------+ | :ref:`StyleBox` | normal | | +---------------------------------+---------------------+------------------------------+ | :ref:`StyleBox` | pressed | | +---------------------------------+---------------------+------------------------------+ Signals ------- .. _class_OptionButton_signal_item_focused: - **item_focused** **(** :ref:`int` index **)** Emitted when the user navigates to an item using the ``ui_up`` or ``ui_down`` actions. The index of the item selected is passed as argument. ---- .. _class_OptionButton_signal_item_selected: - **item_selected** **(** :ref:`int` index **)** Emitted when the current item has been changed by the user. The index of the item selected is passed as argument. Property Descriptions --------------------- .. _class_OptionButton_property_selected: - :ref:`int` **selected** +-----------+----------------+ | *Default* | ``-1`` | +-----------+----------------+ | *Getter* | get_selected() | +-----------+----------------+ The index of the currently selected item, or ``-1`` if no item is selected. Method Descriptions ------------------- .. _class_OptionButton_method_add_icon_item: - void **add_icon_item** **(** :ref:`Texture` texture, :ref:`String` label, :ref:`int` id=-1 **)** 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. ---- .. _class_OptionButton_method_add_item: - void **add_item** **(** :ref:`String` label, :ref:`int` id=-1 **)** 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. ---- .. _class_OptionButton_method_add_separator: - 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. ---- .. _class_OptionButton_method_clear: - void **clear** **(** **)** Clears all the items in the ``OptionButton``. ---- .. _class_OptionButton_method_get_item_count: - :ref:`int` **get_item_count** **(** **)** |const| Returns the amount of items in the OptionButton, including separators. ---- .. _class_OptionButton_method_get_item_icon: - :ref:`Texture` **get_item_icon** **(** :ref:`int` idx **)** |const| Returns the icon of the item at index ``idx``. ---- .. _class_OptionButton_method_get_item_id: - :ref:`int` **get_item_id** **(** :ref:`int` idx **)** |const| Returns the ID of the item at index ``idx``. ---- .. _class_OptionButton_method_get_item_index: - :ref:`int` **get_item_index** **(** :ref:`int` id **)** |const| Returns the index of the item with the given ``id``. ---- .. _class_OptionButton_method_get_item_metadata: - :ref:`Variant` **get_item_metadata** **(** :ref:`int` idx **)** |const| 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. ---- .. _class_OptionButton_method_get_item_text: - :ref:`String` **get_item_text** **(** :ref:`int` idx **)** |const| Returns the text of the item at index ``idx``. ---- .. _class_OptionButton_method_get_popup: - :ref:`PopupMenu` **get_popup** **(** **)** |const| Returns the :ref:`PopupMenu` contained in this button. ---- .. _class_OptionButton_method_get_selected_id: - :ref:`int` **get_selected_id** **(** **)** |const| Returns the ID of the selected item, or ``0`` if no item is selected. ---- .. _class_OptionButton_method_get_selected_metadata: - :ref:`Variant` **get_selected_metadata** **(** **)** |const| Gets the metadata of the selected item. Metadata for items can be set using :ref:`set_item_metadata`. ---- .. _class_OptionButton_method_is_item_disabled: - :ref:`bool` **is_item_disabled** **(** :ref:`int` idx **)** |const| Returns ``true`` if the item at index ``idx`` is disabled. ---- .. _class_OptionButton_method_remove_item: - void **remove_item** **(** :ref:`int` idx **)** Removes the item at index ``idx``. ---- .. _class_OptionButton_method_select: - void **select** **(** :ref:`int` idx **)** Selects an item by index and makes it the current item. This will work even if the item is disabled. ---- .. _class_OptionButton_method_set_item_disabled: - void **set_item_disabled** **(** :ref:`int` idx, :ref:`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. ---- .. _class_OptionButton_method_set_item_icon: - void **set_item_icon** **(** :ref:`int` idx, :ref:`Texture` texture **)** Sets the icon of the item at index ``idx``. ---- .. _class_OptionButton_method_set_item_id: - void **set_item_id** **(** :ref:`int` idx, :ref:`int` id **)** Sets the ID of the item at index ``idx``. ---- .. _class_OptionButton_method_set_item_metadata: - void **set_item_metadata** **(** :ref:`int` idx, :ref:`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. ---- .. _class_OptionButton_method_set_item_text: - void **set_item_text** **(** :ref:`int` idx, :ref:`String` text **)** Sets the text of the item at index ``idx``. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`