mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
658 lines
36 KiB
ReStructuredText
658 lines
36 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. meta::
|
||
:keywords: select, dropdown
|
||
|
||
.. _class_OptionButton:
|
||
|
||
OptionButton
|
||
============
|
||
|
||
**继承:** :ref:`Button<class_Button>` **<** :ref:`BaseButton<class_BaseButton>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
|
||
|
||
按下时弹出下拉菜单的按钮。
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
描述
|
||
----
|
||
|
||
**OptionButton** 是一种按下时弹出下拉菜单的按钮。选中的菜单项会成为“当前”菜单项,作为按钮文本显示。
|
||
|
||
另见 :ref:`BaseButton<class_BaseButton>`\ ,其中包含与此节点相关联的通用属性和方法。
|
||
|
||
\ **注意:**\ 菜单项的 ID 限制为带符号 32 位整数,并不是完整的 64 位 :ref:`int<class_int>`\ 。取值范围为 ``-2^31`` 到 ``2^31 - 1``\ ,即 ``-2147483648`` 到 ``2147483647``\ 。
|
||
|
||
\ **注意:**\ :ref:`Button.text<class_Button_property_text>` 和 :ref:`Button.icon<class_Button_property_icon>` 属性会根据当前所选菜单项自动设置。不应该手动更改。
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
属性
|
||
----
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|
||
| :ref:`ActionMode<enum_BaseButton_ActionMode>` | action_mode | ``0`` (overrides :ref:`BaseButton<class_BaseButton_property_action_mode>`) |
|
||
+-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|
||
| :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` | alignment | ``0`` (overrides :ref:`Button<class_Button_property_alignment>`) |
|
||
+-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`allow_reselect<class_OptionButton_property_allow_reselect>` | ``false`` |
|
||
+-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`fit_to_longest_item<class_OptionButton_property_fit_to_longest_item>` | ``true`` |
|
||
+-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`item_count<class_OptionButton_property_item_count>` | ``0`` |
|
||
+-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`selected<class_OptionButton_property_selected>` | ``-1`` |
|
||
+-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | toggle_mode | ``true`` (overrides :ref:`BaseButton<class_BaseButton_property_toggle_mode>`) |
|
||
+-------------------------------------------------------------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
方法
|
||
----
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`add_icon_item<class_OptionButton_method_add_icon_item>`\ (\ texture\: :ref:`Texture2D<class_Texture2D>`, label\: :ref:`String<class_String>`, id\: :ref:`int<class_int>` = -1\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`add_item<class_OptionButton_method_add_item>`\ (\ label\: :ref:`String<class_String>`, id\: :ref:`int<class_int>` = -1\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`add_separator<class_OptionButton_method_add_separator>`\ (\ text\: :ref:`String<class_String>` = ""\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`clear<class_OptionButton_method_clear>`\ (\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`AutoTranslateMode<enum_Node_AutoTranslateMode>` | :ref:`get_item_auto_translate_mode<class_OptionButton_method_get_item_auto_translate_mode>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Texture2D<class_Texture2D>` | :ref:`get_item_icon<class_OptionButton_method_get_item_icon>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_item_id<class_OptionButton_method_get_item_id>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_item_index<class_OptionButton_method_get_item_index>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`get_item_metadata<class_OptionButton_method_get_item_metadata>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_item_text<class_OptionButton_method_get_item_text>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_item_tooltip<class_OptionButton_method_get_item_tooltip>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PopupMenu<class_PopupMenu>` | :ref:`get_popup<class_OptionButton_method_get_popup>`\ (\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_selectable_item<class_OptionButton_method_get_selectable_item>`\ (\ from_last\: :ref:`bool<class_bool>` = false\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_selected_id<class_OptionButton_method_get_selected_id>`\ (\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`get_selected_metadata<class_OptionButton_method_get_selected_metadata>`\ (\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_selectable_items<class_OptionButton_method_has_selectable_items>`\ (\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_item_disabled<class_OptionButton_method_is_item_disabled>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_item_separator<class_OptionButton_method_is_item_separator>`\ (\ idx\: :ref:`int<class_int>`\ ) |const| |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`remove_item<class_OptionButton_method_remove_item>`\ (\ idx\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`select<class_OptionButton_method_select>`\ (\ idx\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_disable_shortcuts<class_OptionButton_method_set_disable_shortcuts>`\ (\ disabled\: :ref:`bool<class_bool>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_item_auto_translate_mode<class_OptionButton_method_set_item_auto_translate_mode>`\ (\ idx\: :ref:`int<class_int>`, mode\: :ref:`AutoTranslateMode<enum_Node_AutoTranslateMode>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_item_disabled<class_OptionButton_method_set_item_disabled>`\ (\ idx\: :ref:`int<class_int>`, disabled\: :ref:`bool<class_bool>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_item_icon<class_OptionButton_method_set_item_icon>`\ (\ idx\: :ref:`int<class_int>`, texture\: :ref:`Texture2D<class_Texture2D>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_item_id<class_OptionButton_method_set_item_id>`\ (\ idx\: :ref:`int<class_int>`, id\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_item_metadata<class_OptionButton_method_set_item_metadata>`\ (\ idx\: :ref:`int<class_int>`, metadata\: :ref:`Variant<class_Variant>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_item_text<class_OptionButton_method_set_item_text>`\ (\ idx\: :ref:`int<class_int>`, text\: :ref:`String<class_String>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_item_tooltip<class_OptionButton_method_set_item_tooltip>`\ (\ idx\: :ref:`int<class_int>`, tooltip\: :ref:`String<class_String>`\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`show_popup<class_OptionButton_method_show_popup>`\ (\ ) |
|
||
+-------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
主题属性
|
||
--------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-----------------------------------+-------------------------------------------------------------------------+-------+
|
||
| :ref:`int<class_int>` | :ref:`arrow_margin<class_OptionButton_theme_constant_arrow_margin>` | ``4`` |
|
||
+-----------------------------------+-------------------------------------------------------------------------+-------+
|
||
| :ref:`int<class_int>` | :ref:`modulate_arrow<class_OptionButton_theme_constant_modulate_arrow>` | ``0`` |
|
||
+-----------------------------------+-------------------------------------------------------------------------+-------+
|
||
| :ref:`Texture2D<class_Texture2D>` | :ref:`arrow<class_OptionButton_theme_icon_arrow>` | |
|
||
+-----------------------------------+-------------------------------------------------------------------------+-------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
信号
|
||
----
|
||
|
||
.. _class_OptionButton_signal_item_focused:
|
||
|
||
.. rst-class:: classref-signal
|
||
|
||
**item_focused**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_signal_item_focused>`
|
||
|
||
当用户使用 :ref:`ProjectSettings.input/ui_up<class_ProjectSettings_property_input/ui_up>` 或 :ref:`ProjectSettings.input/ui_down<class_ProjectSettings_property_input/ui_down>` 输入动作导航到某个项目时发出。所选项目的索引将作为参数传递。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_signal_item_selected:
|
||
|
||
.. rst-class:: classref-signal
|
||
|
||
**item_selected**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_signal_item_selected>`
|
||
|
||
当用户更改当前项时触发。所选项目的索引作为参数传递。
|
||
|
||
必须启用 :ref:`allow_reselect<class_OptionButton_property_allow_reselect>` 才能重新选中项目。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
属性说明
|
||
--------
|
||
|
||
.. _class_OptionButton_property_allow_reselect:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`bool<class_bool>` **allow_reselect** = ``false`` :ref:`🔗<class_OptionButton_property_allow_reselect>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_allow_reselect**\ (\ value\: :ref:`bool<class_bool>`\ )
|
||
- :ref:`bool<class_bool>` **get_allow_reselect**\ (\ )
|
||
|
||
如果为 ``true``\ ,则可以再次选择当前选中的项目。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_property_fit_to_longest_item:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`bool<class_bool>` **fit_to_longest_item** = ``true`` :ref:`🔗<class_OptionButton_property_fit_to_longest_item>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_fit_to_longest_item**\ (\ value\: :ref:`bool<class_bool>`\ )
|
||
- :ref:`bool<class_bool>` **is_fit_to_longest_item**\ (\ )
|
||
|
||
如果为 ``true``\ ,最小尺寸将由最长项目的文本确定,而不是当前选定的文本。
|
||
|
||
\ **注意:**\ 出于性能原因,在添加、移除或修改项目时,最小尺寸不会立即更新。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_property_item_count:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`int<class_int>` **item_count** = ``0`` :ref:`🔗<class_OptionButton_property_item_count>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_item_count**\ (\ value\: :ref:`int<class_int>`\ )
|
||
- :ref:`int<class_int>` **get_item_count**\ (\ )
|
||
|
||
可供挑选的菜单项的数量。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_property_selected:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`int<class_int>` **selected** = ``-1`` :ref:`🔗<class_OptionButton_property_selected>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- :ref:`int<class_int>` **get_selected**\ (\ )
|
||
|
||
当前选定项的索引,如果没有选定项,则为\ ``-1``\ 。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
方法说明
|
||
--------
|
||
|
||
.. _class_OptionButton_method_add_icon_item:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **add_icon_item**\ (\ texture\: :ref:`Texture2D<class_Texture2D>`, label\: :ref:`String<class_String>`, id\: :ref:`int<class_int>` = -1\ ) :ref:`🔗<class_OptionButton_method_add_icon_item>`
|
||
|
||
添加一个菜单项,图标为 ``texture``\ ,文本为 ``label``\ ,(可选)ID 为 ``id``\ 。如果没有传入 ``id``\ ,则会将菜单项的索引用作 ID。新菜单项会追加到末尾。
|
||
|
||
\ **注意:**\ 没有其他菜单项时会选中该菜单项。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_add_item:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **add_item**\ (\ label\: :ref:`String<class_String>`, id\: :ref:`int<class_int>` = -1\ ) :ref:`🔗<class_OptionButton_method_add_item>`
|
||
|
||
添加一个菜单项,文本为 ``label``\ ,(可选)ID 为 ``id``\ 。如果没有传入 ``id``\ ,则会将菜单项的索引用作 ID。新菜单项会追加到末尾。
|
||
|
||
\ **注意:**\ 没有其他菜单项时会选中该菜单项。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_add_separator:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **add_separator**\ (\ text\: :ref:`String<class_String>` = ""\ ) :ref:`🔗<class_OptionButton_method_add_separator>`
|
||
|
||
在菜单项列表中添加分隔符。分隔符可以用来对菜单项进行分组,还可以给出标题文本 ``text``\ 。分隔符也设有索引,会追加到菜单项列表的末尾。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_clear:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **clear**\ (\ ) :ref:`🔗<class_OptionButton_method_clear>`
|
||
|
||
清除\ **OptionButton**\ 中的所有项目。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_item_auto_translate_mode:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`AutoTranslateMode<enum_Node_AutoTranslateMode>` **get_item_auto_translate_mode**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_auto_translate_mode>`
|
||
|
||
返回索引为 ``idx`` 的菜单项的自动翻译模式。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_item_icon:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Texture2D<class_Texture2D>` **get_item_icon**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_icon>`
|
||
|
||
返回索引为 ``idx`` 的菜单项的图标。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_item_id:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_item_id**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_id>`
|
||
|
||
返回索引为 ``idx`` 的菜单项的 ID。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_item_index:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_item_index**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_index>`
|
||
|
||
返回 ID 为 ``id`` 的菜单项的索引。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_item_metadata:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **get_item_metadata**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_metadata>`
|
||
|
||
检索项的元数据。元数据可以是任何类型,并可用于存储关于项的额外信息,如外部字符串ID。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_item_text:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_item_text**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_text>`
|
||
|
||
返回索引为 ``idx`` 的菜单项的文本。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_item_tooltip:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_item_tooltip**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_get_item_tooltip>`
|
||
|
||
返回索引为 ``idx`` 的菜单项的工具提示。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_popup:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PopupMenu<class_PopupMenu>` **get_popup**\ (\ ) |const| :ref:`🔗<class_OptionButton_method_get_popup>`
|
||
|
||
返回这个按钮中包含的 :ref:`PopupMenu<class_PopupMenu>`\ 。
|
||
|
||
\ **警告:**\ 这是一个必需的内部节点,移除和释放它可能会导致崩溃。如果你想隐藏它或它的任何子节点,请使用其 :ref:`Window.visible<class_Window_property_visible>` 属性。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_selectable_item:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_selectable_item**\ (\ from_last\: :ref:`bool<class_bool>` = false\ ) |const| :ref:`🔗<class_OptionButton_method_get_selectable_item>`
|
||
|
||
返回第一个处于非禁用状态或被标记为分隔符的菜单项的索引。如果 ``from_last`` 为 ``true``\ ,则会逆序搜索菜单项。
|
||
|
||
如果没有找到则返回 ``-1``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_selected_id:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_selected_id**\ (\ ) |const| :ref:`🔗<class_OptionButton_method_get_selected_id>`
|
||
|
||
返回所选项目的 ID,如果没有选择项目,则返回 ``-1``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_get_selected_metadata:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **get_selected_metadata**\ (\ ) |const| :ref:`🔗<class_OptionButton_method_get_selected_metadata>`
|
||
|
||
获取选定项的元数据。可以使用 :ref:`set_item_metadata()<class_OptionButton_method_set_item_metadata>` 设置项的元数据。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_has_selectable_items:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_selectable_items**\ (\ ) |const| :ref:`🔗<class_OptionButton_method_has_selectable_items>`
|
||
|
||
如果这个按钮至少包含一个未禁用或被标记为分隔符的菜单项,则返回 ``true``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_is_item_disabled:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_item_disabled**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_is_item_disabled>`
|
||
|
||
如果索引为 ``idx`` 的菜单项被禁用,则返回 ``true``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_is_item_separator:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_item_separator**\ (\ idx\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_OptionButton_method_is_item_separator>`
|
||
|
||
如果索引为 ``idx`` 的菜单项被标记为分隔符,则返回 ``true``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_remove_item:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **remove_item**\ (\ idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_method_remove_item>`
|
||
|
||
移除索引为 ``idx`` 的菜单项。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_select:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **select**\ (\ idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_method_select>`
|
||
|
||
按索引选择项并使其为当前选中项。即使该项是禁用的,这也将起作用。
|
||
|
||
将 ``-1`` 作为索引传入会取消选中任何当前选中的项目。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_set_disable_shortcuts:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_disable_shortcuts**\ (\ disabled\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_OptionButton_method_set_disable_shortcuts>`
|
||
|
||
如果为 ``true``\ ,快捷方式将被禁用,无法用于触发按钮。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_set_item_auto_translate_mode:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_item_auto_translate_mode**\ (\ idx\: :ref:`int<class_int>`, mode\: :ref:`AutoTranslateMode<enum_Node_AutoTranslateMode>`\ ) :ref:`🔗<class_OptionButton_method_set_item_auto_translate_mode>`
|
||
|
||
设置索引为 ``idx`` 的菜单项的自动翻译模式。
|
||
|
||
菜单项使用 :ref:`Node.AUTO_TRANSLATE_MODE_INHERIT<class_Node_constant_AUTO_TRANSLATE_MODE_INHERIT>`\ ,表示使用与 **OptionButton** 相同的自动翻译模式。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_set_item_disabled:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_item_disabled**\ (\ idx\: :ref:`int<class_int>`, disabled\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_OptionButton_method_set_item_disabled>`
|
||
|
||
设置是否禁用索引为 ``idx`` 的菜单项。
|
||
|
||
处于禁用状态的菜单项在下拉列表中绘制的方式不同,用户无法选中这个菜单项。如果将当前选中的菜单项设为了禁用,则仍然会处于选中状态。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_set_item_icon:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_item_icon**\ (\ idx\: :ref:`int<class_int>`, texture\: :ref:`Texture2D<class_Texture2D>`\ ) :ref:`🔗<class_OptionButton_method_set_item_icon>`
|
||
|
||
设置索引为 ``idx`` 的菜单项的图标。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_set_item_id:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_item_id**\ (\ idx\: :ref:`int<class_int>`, id\: :ref:`int<class_int>`\ ) :ref:`🔗<class_OptionButton_method_set_item_id>`
|
||
|
||
设置索引为 ``idx`` 的菜单项的 ID。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_set_item_metadata:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_item_metadata**\ (\ idx\: :ref:`int<class_int>`, metadata\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_OptionButton_method_set_item_metadata>`
|
||
|
||
设置项的元数据。元数据可以是任何类型,可以用来存储关于项目的额外信息,比如外部字符串ID。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_set_item_text:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_item_text**\ (\ idx\: :ref:`int<class_int>`, text\: :ref:`String<class_String>`\ ) :ref:`🔗<class_OptionButton_method_set_item_text>`
|
||
|
||
设置索引为 ``idx`` 的菜单项的文本。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_set_item_tooltip:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_item_tooltip**\ (\ idx\: :ref:`int<class_int>`, tooltip\: :ref:`String<class_String>`\ ) :ref:`🔗<class_OptionButton_method_set_item_tooltip>`
|
||
|
||
设置索引为 ``idx`` 的菜单项的工具提示。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_method_show_popup:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **show_popup**\ (\ ) :ref:`🔗<class_OptionButton_method_show_popup>`
|
||
|
||
调整 **OptionButton** 弹出项的位置和大小,然后显示 :ref:`PopupMenu<class_PopupMenu>`\ 。请优先使用这个方法,而不是 ``get_popup().popup()``\ 。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
主题属性说明
|
||
------------
|
||
|
||
.. _class_OptionButton_theme_constant_arrow_margin:
|
||
|
||
.. rst-class:: classref-themeproperty
|
||
|
||
:ref:`int<class_int>` **arrow_margin** = ``4`` :ref:`🔗<class_OptionButton_theme_constant_arrow_margin>`
|
||
|
||
箭头图标和按钮的右边缘之间的水平空间。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_theme_constant_modulate_arrow:
|
||
|
||
.. rst-class:: classref-themeproperty
|
||
|
||
:ref:`int<class_int>` **modulate_arrow** = ``0`` :ref:`🔗<class_OptionButton_theme_constant_modulate_arrow>`
|
||
|
||
如果不为 ``0``\ ,箭头图标会与字体颜色进行调制。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_OptionButton_theme_icon_arrow:
|
||
|
||
.. rst-class:: classref-themeproperty
|
||
|
||
:ref:`Texture2D<class_Texture2D>` **arrow** :ref:`🔗<class_OptionButton_theme_icon_arrow>`
|
||
|
||
要绘制在按钮右侧的箭头图标。
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
|
||
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
|
||
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
|
||
.. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)`
|
||
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)`
|
||
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)`
|
||
.. |void| replace:: :abbr:`void (无返回值。)`
|