class_optionbutton.rst 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/OptionButton.xml.
  6. .. _class_OptionButton:
  7. OptionButton
  8. ============
  9. **Inherits:** :ref:`Button<class_Button>` **<** :ref:`BaseButton<class_BaseButton>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. A button that brings up a dropdown with selectable options when pressed.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **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.
  15. See also :ref:`BaseButton<class_BaseButton>` which contains common properties and methods associated with this node.
  16. \ **Note:** The ID values used for items are limited to 32 bits, not full 64 bits of :ref:`int<class_int>`. This has a range of ``-2^32`` to ``2^32 - 1``, i.e. ``-2147483648`` to ``2147483647``.
  17. \ **Note:** The :ref:`Button.text<class_Button_property_text>` and :ref:`Button.icon<class_Button_property_icon>` properties are set automatically based on the selected item. They shouldn't be changed manually.
  18. .. rst-class:: classref-reftable-group
  19. Properties
  20. ----------
  21. .. table::
  22. :widths: auto
  23. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  24. | :ref:`ActionMode<enum_BaseButton_ActionMode>` | action_mode | ``0`` (overrides :ref:`BaseButton<class_BaseButton_property_action_mode>`) |
  25. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  26. | :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` | alignment | ``0`` (overrides :ref:`Button<class_Button_property_alignment>`) |
  27. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`allow_reselect<class_OptionButton_property_allow_reselect>` | ``false`` |
  29. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`fit_to_longest_item<class_OptionButton_property_fit_to_longest_item>` | ``true`` |
  31. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`item_count<class_OptionButton_property_item_count>` | ``0`` |
  33. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`selected<class_OptionButton_property_selected>` | ``-1`` |
  35. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | toggle_mode | ``true`` (overrides :ref:`BaseButton<class_BaseButton_property_toggle_mode>`) |
  37. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
  38. .. rst-class:: classref-reftable-group
  39. Methods
  40. -------
  41. .. table::
  42. :widths: auto
  43. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | void | :ref:`add_icon_item<class_OptionButton_method_add_icon_item>` **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)** |
  45. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`add_item<class_OptionButton_method_add_item>` **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)** |
  47. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`add_separator<class_OptionButton_method_add_separator>` **(** :ref:`String<class_String>` text="" **)** |
  49. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`clear<class_OptionButton_method_clear>` **(** **)** |
  51. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Texture2D<class_Texture2D>` | :ref:`get_item_icon<class_OptionButton_method_get_item_icon>` **(** :ref:`int<class_int>` idx **)** |const| |
  53. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`int<class_int>` | :ref:`get_item_id<class_OptionButton_method_get_item_id>` **(** :ref:`int<class_int>` idx **)** |const| |
  55. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`int<class_int>` | :ref:`get_item_index<class_OptionButton_method_get_item_index>` **(** :ref:`int<class_int>` id **)** |const| |
  57. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`Variant<class_Variant>` | :ref:`get_item_metadata<class_OptionButton_method_get_item_metadata>` **(** :ref:`int<class_int>` idx **)** |const| |
  59. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`String<class_String>` | :ref:`get_item_text<class_OptionButton_method_get_item_text>` **(** :ref:`int<class_int>` idx **)** |const| |
  61. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`String<class_String>` | :ref:`get_item_tooltip<class_OptionButton_method_get_item_tooltip>` **(** :ref:`int<class_int>` idx **)** |const| |
  63. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_OptionButton_method_get_popup>` **(** **)** |const| |
  65. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`int<class_int>` | :ref:`get_selectable_item<class_OptionButton_method_get_selectable_item>` **(** :ref:`bool<class_bool>` from_last=false **)** |const| |
  67. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`int<class_int>` | :ref:`get_selected_id<class_OptionButton_method_get_selected_id>` **(** **)** |const| |
  69. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Variant<class_Variant>` | :ref:`get_selected_metadata<class_OptionButton_method_get_selected_metadata>` **(** **)** |const| |
  71. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`bool<class_bool>` | :ref:`has_selectable_items<class_OptionButton_method_has_selectable_items>` **(** **)** |const| |
  73. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`bool<class_bool>` | :ref:`is_item_disabled<class_OptionButton_method_is_item_disabled>` **(** :ref:`int<class_int>` idx **)** |const| |
  75. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`bool<class_bool>` | :ref:`is_item_separator<class_OptionButton_method_is_item_separator>` **(** :ref:`int<class_int>` idx **)** |const| |
  77. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`remove_item<class_OptionButton_method_remove_item>` **(** :ref:`int<class_int>` idx **)** |
  79. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`select<class_OptionButton_method_select>` **(** :ref:`int<class_int>` idx **)** |
  81. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`set_disable_shortcuts<class_OptionButton_method_set_disable_shortcuts>` **(** :ref:`bool<class_bool>` disabled **)** |
  83. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | void | :ref:`set_item_disabled<class_OptionButton_method_set_item_disabled>` **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)** |
  85. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | void | :ref:`set_item_icon<class_OptionButton_method_set_item_icon>` **(** :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture **)** |
  87. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | void | :ref:`set_item_id<class_OptionButton_method_set_item_id>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)** |
  89. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | void | :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>` **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)** |
  91. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | void | :ref:`set_item_text<class_OptionButton_method_set_item_text>` **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)** |
  93. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | void | :ref:`set_item_tooltip<class_OptionButton_method_set_item_tooltip>` **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` tooltip **)** |
  95. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | void | :ref:`show_popup<class_OptionButton_method_show_popup>` **(** **)** |
  97. +-----------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. .. rst-class:: classref-reftable-group
  99. Theme Properties
  100. ----------------
  101. .. table::
  102. :widths: auto
  103. +-----------------------------------+-------------------------------------------------------------------------+-------+
  104. | :ref:`int<class_int>` | :ref:`arrow_margin<class_OptionButton_theme_constant_arrow_margin>` | ``4`` |
  105. +-----------------------------------+-------------------------------------------------------------------------+-------+
  106. | :ref:`int<class_int>` | :ref:`modulate_arrow<class_OptionButton_theme_constant_modulate_arrow>` | ``0`` |
  107. +-----------------------------------+-------------------------------------------------------------------------+-------+
  108. | :ref:`Texture2D<class_Texture2D>` | :ref:`arrow<class_OptionButton_theme_icon_arrow>` | |
  109. +-----------------------------------+-------------------------------------------------------------------------+-------+
  110. .. rst-class:: classref-section-separator
  111. ----
  112. .. rst-class:: classref-descriptions-group
  113. Signals
  114. -------
  115. .. _class_OptionButton_signal_item_focused:
  116. .. rst-class:: classref-signal
  117. **item_focused** **(** :ref:`int<class_int>` index **)**
  118. Emitted when the user navigates to an item using the :ref:`ProjectSettings.input/ui_up<class_ProjectSettings_property_input/ui_up>` or :ref:`ProjectSettings.input/ui_down<class_ProjectSettings_property_input/ui_down>` input actions. The index of the item selected is passed as argument.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_OptionButton_signal_item_selected:
  122. .. rst-class:: classref-signal
  123. **item_selected** **(** :ref:`int<class_int>` index **)**
  124. Emitted when the current item has been changed by the user. The index of the item selected is passed as argument.
  125. \ :ref:`allow_reselect<class_OptionButton_property_allow_reselect>` must be enabled to reselect an item.
  126. .. rst-class:: classref-section-separator
  127. ----
  128. .. rst-class:: classref-descriptions-group
  129. Property Descriptions
  130. ---------------------
  131. .. _class_OptionButton_property_allow_reselect:
  132. .. rst-class:: classref-property
  133. :ref:`bool<class_bool>` **allow_reselect** = ``false``
  134. .. rst-class:: classref-property-setget
  135. - void **set_allow_reselect** **(** :ref:`bool<class_bool>` value **)**
  136. - :ref:`bool<class_bool>` **get_allow_reselect** **(** **)**
  137. If ``true``, the currently selected item can be selected again.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_OptionButton_property_fit_to_longest_item:
  141. .. rst-class:: classref-property
  142. :ref:`bool<class_bool>` **fit_to_longest_item** = ``true``
  143. .. rst-class:: classref-property-setget
  144. - void **set_fit_to_longest_item** **(** :ref:`bool<class_bool>` value **)**
  145. - :ref:`bool<class_bool>` **is_fit_to_longest_item** **(** **)**
  146. If ``true``, minimum size will be determined by the longest item's text, instead of the currently selected one's.
  147. \ **Note:** For performance reasons, the minimum size doesn't update immediately when adding, removing or modifying items.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_OptionButton_property_item_count:
  151. .. rst-class:: classref-property
  152. :ref:`int<class_int>` **item_count** = ``0``
  153. .. rst-class:: classref-property-setget
  154. - void **set_item_count** **(** :ref:`int<class_int>` value **)**
  155. - :ref:`int<class_int>` **get_item_count** **(** **)**
  156. The number of items to select from.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_OptionButton_property_selected:
  160. .. rst-class:: classref-property
  161. :ref:`int<class_int>` **selected** = ``-1``
  162. .. rst-class:: classref-property-setget
  163. - :ref:`int<class_int>` **get_selected** **(** **)**
  164. The index of the currently selected item, or ``-1`` if no item is selected.
  165. .. rst-class:: classref-section-separator
  166. ----
  167. .. rst-class:: classref-descriptions-group
  168. Method Descriptions
  169. -------------------
  170. .. _class_OptionButton_method_add_icon_item:
  171. .. rst-class:: classref-method
  172. void **add_icon_item** **(** :ref:`Texture2D<class_Texture2D>` texture, :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  173. 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.
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_OptionButton_method_add_item:
  177. .. rst-class:: classref-method
  178. void **add_item** **(** :ref:`String<class_String>` label, :ref:`int<class_int>` id=-1 **)**
  179. 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.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_OptionButton_method_add_separator:
  183. .. rst-class:: classref-method
  184. void **add_separator** **(** :ref:`String<class_String>` text="" **)**
  185. 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.
  186. .. rst-class:: classref-item-separator
  187. ----
  188. .. _class_OptionButton_method_clear:
  189. .. rst-class:: classref-method
  190. void **clear** **(** **)**
  191. Clears all the items in the **OptionButton**.
  192. .. rst-class:: classref-item-separator
  193. ----
  194. .. _class_OptionButton_method_get_item_icon:
  195. .. rst-class:: classref-method
  196. :ref:`Texture2D<class_Texture2D>` **get_item_icon** **(** :ref:`int<class_int>` idx **)** |const|
  197. Returns the icon of the item at index ``idx``.
  198. .. rst-class:: classref-item-separator
  199. ----
  200. .. _class_OptionButton_method_get_item_id:
  201. .. rst-class:: classref-method
  202. :ref:`int<class_int>` **get_item_id** **(** :ref:`int<class_int>` idx **)** |const|
  203. Returns the ID of the item at index ``idx``.
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. _class_OptionButton_method_get_item_index:
  207. .. rst-class:: classref-method
  208. :ref:`int<class_int>` **get_item_index** **(** :ref:`int<class_int>` id **)** |const|
  209. Returns the index of the item with the given ``id``.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_OptionButton_method_get_item_metadata:
  213. .. rst-class:: classref-method
  214. :ref:`Variant<class_Variant>` **get_item_metadata** **(** :ref:`int<class_int>` idx **)** |const|
  215. 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.
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_OptionButton_method_get_item_text:
  219. .. rst-class:: classref-method
  220. :ref:`String<class_String>` **get_item_text** **(** :ref:`int<class_int>` idx **)** |const|
  221. Returns the text of the item at index ``idx``.
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_OptionButton_method_get_item_tooltip:
  225. .. rst-class:: classref-method
  226. :ref:`String<class_String>` **get_item_tooltip** **(** :ref:`int<class_int>` idx **)** |const|
  227. Returns the tooltip of the item at index ``idx``.
  228. .. rst-class:: classref-item-separator
  229. ----
  230. .. _class_OptionButton_method_get_popup:
  231. .. rst-class:: classref-method
  232. :ref:`PopupMenu<class_PopupMenu>` **get_popup** **(** **)** |const|
  233. Returns the :ref:`PopupMenu<class_PopupMenu>` contained in this button.
  234. \ **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 :ref:`Window.visible<class_Window_property_visible>` property.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_OptionButton_method_get_selectable_item:
  238. .. rst-class:: classref-method
  239. :ref:`int<class_int>` **get_selectable_item** **(** :ref:`bool<class_bool>` from_last=false **)** |const|
  240. 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.
  241. Returns ``-1`` if no item is found.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_OptionButton_method_get_selected_id:
  245. .. rst-class:: classref-method
  246. :ref:`int<class_int>` **get_selected_id** **(** **)** |const|
  247. Returns the ID of the selected item, or ``-1`` if no item is selected.
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_OptionButton_method_get_selected_metadata:
  251. .. rst-class:: classref-method
  252. :ref:`Variant<class_Variant>` **get_selected_metadata** **(** **)** |const|
  253. Gets the metadata of the selected item. Metadata for items can be set using :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>`.
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_OptionButton_method_has_selectable_items:
  257. .. rst-class:: classref-method
  258. :ref:`bool<class_bool>` **has_selectable_items** **(** **)** |const|
  259. Returns ``true`` if this button contains at least one item which is not disabled, or marked as a separator.
  260. .. rst-class:: classref-item-separator
  261. ----
  262. .. _class_OptionButton_method_is_item_disabled:
  263. .. rst-class:: classref-method
  264. :ref:`bool<class_bool>` **is_item_disabled** **(** :ref:`int<class_int>` idx **)** |const|
  265. Returns ``true`` if the item at index ``idx`` is disabled.
  266. .. rst-class:: classref-item-separator
  267. ----
  268. .. _class_OptionButton_method_is_item_separator:
  269. .. rst-class:: classref-method
  270. :ref:`bool<class_bool>` **is_item_separator** **(** :ref:`int<class_int>` idx **)** |const|
  271. Returns ``true`` if the item at index ``idx`` is marked as a separator.
  272. .. rst-class:: classref-item-separator
  273. ----
  274. .. _class_OptionButton_method_remove_item:
  275. .. rst-class:: classref-method
  276. void **remove_item** **(** :ref:`int<class_int>` idx **)**
  277. Removes the item at index ``idx``.
  278. .. rst-class:: classref-item-separator
  279. ----
  280. .. _class_OptionButton_method_select:
  281. .. rst-class:: classref-method
  282. void **select** **(** :ref:`int<class_int>` idx **)**
  283. Selects an item by index and makes it the current item. This will work even if the item is disabled.
  284. Passing ``-1`` as the index deselects any currently selected item.
  285. .. rst-class:: classref-item-separator
  286. ----
  287. .. _class_OptionButton_method_set_disable_shortcuts:
  288. .. rst-class:: classref-method
  289. void **set_disable_shortcuts** **(** :ref:`bool<class_bool>` disabled **)**
  290. If ``true``, shortcuts are disabled and cannot be used to trigger the button.
  291. .. rst-class:: classref-item-separator
  292. ----
  293. .. _class_OptionButton_method_set_item_disabled:
  294. .. rst-class:: classref-method
  295. void **set_item_disabled** **(** :ref:`int<class_int>` idx, :ref:`bool<class_bool>` disabled **)**
  296. Sets whether the item at index ``idx`` is disabled.
  297. 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.
  298. .. rst-class:: classref-item-separator
  299. ----
  300. .. _class_OptionButton_method_set_item_icon:
  301. .. rst-class:: classref-method
  302. void **set_item_icon** **(** :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture **)**
  303. Sets the icon of the item at index ``idx``.
  304. .. rst-class:: classref-item-separator
  305. ----
  306. .. _class_OptionButton_method_set_item_id:
  307. .. rst-class:: classref-method
  308. void **set_item_id** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` id **)**
  309. Sets the ID of the item at index ``idx``.
  310. .. rst-class:: classref-item-separator
  311. ----
  312. .. _class_OptionButton_method_set_item_metadata:
  313. .. rst-class:: classref-method
  314. void **set_item_metadata** **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` metadata **)**
  315. 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.
  316. .. rst-class:: classref-item-separator
  317. ----
  318. .. _class_OptionButton_method_set_item_text:
  319. .. rst-class:: classref-method
  320. void **set_item_text** **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` text **)**
  321. Sets the text of the item at index ``idx``.
  322. .. rst-class:: classref-item-separator
  323. ----
  324. .. _class_OptionButton_method_set_item_tooltip:
  325. .. rst-class:: classref-method
  326. void **set_item_tooltip** **(** :ref:`int<class_int>` idx, :ref:`String<class_String>` tooltip **)**
  327. Sets the tooltip of the item at index ``idx``.
  328. .. rst-class:: classref-item-separator
  329. ----
  330. .. _class_OptionButton_method_show_popup:
  331. .. rst-class:: classref-method
  332. void **show_popup** **(** **)**
  333. Adjusts popup position and sizing for the **OptionButton**, then shows the :ref:`PopupMenu<class_PopupMenu>`. Prefer this over using ``get_popup().popup()``.
  334. .. rst-class:: classref-section-separator
  335. ----
  336. .. rst-class:: classref-descriptions-group
  337. Theme Property Descriptions
  338. ---------------------------
  339. .. _class_OptionButton_theme_constant_arrow_margin:
  340. .. rst-class:: classref-themeproperty
  341. :ref:`int<class_int>` **arrow_margin** = ``4``
  342. The horizontal space between the arrow icon and the right edge of the button.
  343. .. rst-class:: classref-item-separator
  344. ----
  345. .. _class_OptionButton_theme_constant_modulate_arrow:
  346. .. rst-class:: classref-themeproperty
  347. :ref:`int<class_int>` **modulate_arrow** = ``0``
  348. If different than ``0``, the arrow icon will be modulated to the font color.
  349. .. rst-class:: classref-item-separator
  350. ----
  351. .. _class_OptionButton_theme_icon_arrow:
  352. .. rst-class:: classref-themeproperty
  353. :ref:`Texture2D<class_Texture2D>` **arrow**
  354. The arrow icon to be drawn on the right end of the button.
  355. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  356. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  357. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  358. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  359. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  360. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  361. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`