Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

PopupMenu

繼承: Popup < Window < Viewport < Node < Object

用於顯示選項列表的模態視窗。

說明

PopupMenu is a modal window used to display a list of options. Useful for toolbars and context menus.

The size of a PopupMenu can be limited by using Window.max_size. If the height of the list of items is larger than the maximum height of the PopupMenu, a ScrollContainer within the popup will allow the user to scroll the contents. If no maximum size is set, or if it is set to 0, the PopupMenu height will be limited by its parent rect.

All set_* methods allow negative item indices, i.e. -1 to access the last item, -2 to select the second-to-last item, and so on.

Incremental search: Like ItemList and Tree, PopupMenu supports searching within the list while the control is focused. Press a key that matches the first letter of an item's name to select the first item starting with the given letter. After that point, there are two ways to perform incremental search: 1) Press the same key again before the timeout duration to select the next item starting with the same letter. 2) Press letter keys that match the rest of the word before the timeout duration to match to select the item in question directly. Both of these actions will be reset to the beginning of the list if the timeout duration has passed since the last keystroke was registered. You can adjust the timeout duration by changing ProjectSettings.gui/timers/incremental_search_max_interval_msec.

Note: PopupMenu is invisible by default. To make it visible, call one of the popup_* methods from Window on the node, such as Window.popup_centered_clamped().

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.

屬性

bool

allow_search

true

DefaultCanvasItemTextureFilter

canvas_item_default_texture_filter

4 (overrides Viewport)

DefaultCanvasItemTextureRepeat

canvas_item_default_texture_repeat

3 (overrides Viewport)

bool

hide_on_checkable_item_selection

true

bool

hide_on_item_selection

true

bool

hide_on_state_item_selection

false

int

item_count

0

int

item_{index}/checkable

0

bool

item_{index}/checked

false

bool

item_{index}/disabled

false

Texture2D

item_{index}/icon

int

item_{index}/id

0

bool

item_{index}/separator

false

String

item_{index}/text

""

bool

prefer_native_menu

false

bool

search_bar_enabled

false

bool

search_bar_fuzzy_search_enabled

true

int

search_bar_fuzzy_search_max_misses

2

int

search_bar_min_item_count

0

bool

shrink_height

true

bool

shrink_width

true

float

submenu_popup_delay

0.2

SystemMenus

system_menu_id

0

bool

transparent

true (overrides Window)

bool

transparent_bg

true (overrides Viewport)

方法

bool

activate_item_by_event(event: InputEvent, for_global_only: bool = false)

void

add_check_item(label: String, id: int = -1, accel: Key = 0)

void

add_check_shortcut(shortcut: Shortcut, id: int = -1, global: bool = false)

void

add_icon_check_item(texture: Texture2D, label: String, id: int = -1, accel: Key = 0)

void

add_icon_check_shortcut(texture: Texture2D, shortcut: Shortcut, id: int = -1, global: bool = false)

void

add_icon_item(texture: Texture2D, label: String, id: int = -1, accel: Key = 0)

void

add_icon_radio_check_item(texture: Texture2D, label: String, id: int = -1, accel: Key = 0)

void

add_icon_radio_check_shortcut(texture: Texture2D, shortcut: Shortcut, id: int = -1, global: bool = false)

void

add_icon_shortcut(texture: Texture2D, shortcut: Shortcut, id: int = -1, global: bool = false, allow_echo: bool = false)

void

add_item(label: String, id: int = -1, accel: Key = 0)

void

add_multistate_item(label: String, max_states: int, default_state: int = 0, id: int = -1, accel: Key = 0)

void

add_radio_check_item(label: String, id: int = -1, accel: Key = 0)

void

add_radio_check_shortcut(shortcut: Shortcut, id: int = -1, global: bool = false)

void

add_separator(label: String = "", id: int = -1)

void

add_shortcut(shortcut: Shortcut, id: int = -1, global: bool = false, allow_echo: bool = false)

void

add_submenu_item(label: String, submenu: String, id: int = -1)

void

add_submenu_node_item(label: String, submenu: PopupMenu, id: int = -1)

void

clear(free_submenus: bool = false)

int

get_focused_item() const

Key

get_item_accelerator(index: int) const

AutoTranslateMode

get_item_auto_translate_mode(index: int) const

Texture2D

get_item_icon(index: int) const

int

get_item_icon_max_width(index: int) const

Color

get_item_icon_modulate(index: int) const

int

get_item_id(index: int) const

int

get_item_indent(index: int) const

int

get_item_index(id: int) const

String

get_item_language(index: int) const

Variant

get_item_metadata(index: int) const

int

get_item_multistate(index: int) const

int

get_item_multistate_max(index: int) const

Shortcut

get_item_shortcut(index: int) const

String

get_item_submenu(index: int) const

PopupMenu

get_item_submenu_node(index: int) const

String

get_item_text(index: int) const

TextDirection

get_item_text_direction(index: int) const

String

get_item_tooltip(index: int) const

bool

is_item_checkable(index: int) const

bool

is_item_checked(index: int) const

bool

is_item_disabled(index: int) const

bool

is_item_radio_checkable(index: int) const

bool

is_item_separator(index: int) const

bool

is_item_shortcut_disabled(index: int) const

bool

is_native_menu() const

bool

is_system_menu() const

void

remove_item(index: int)

void

scroll_to_item(index: int)

void

set_focused_item(index: int)

void

set_item_accelerator(index: int, accel: Key)

void

set_item_as_checkable(index: int, enable: bool)

void

set_item_as_radio_checkable(index: int, enable: bool)

void

set_item_as_separator(index: int, enable: bool)

void

set_item_auto_translate_mode(index: int, mode: AutoTranslateMode)

void

set_item_checked(index: int, checked: bool)

void

set_item_disabled(index: int, disabled: bool)

void

set_item_icon(index: int, icon: Texture2D)

void

set_item_icon_max_width(index: int, width: int)

void

set_item_icon_modulate(index: int, modulate: Color)

void

set_item_id(index: int, id: int)

void

set_item_indent(index: int, indent: int)

void

set_item_index(index: int, target_index: int)

void

set_item_language(index: int, language: String)

void

set_item_metadata(index: int, metadata: Variant)

void

set_item_multistate(index: int, state: int)

void

set_item_multistate_max(index: int, max_states: int)

void

set_item_shortcut(index: int, shortcut: Shortcut, global: bool = false)

void

set_item_shortcut_disabled(index: int, disabled: bool)

void

set_item_submenu(index: int, submenu: String)

void

set_item_submenu_node(index: int, submenu: PopupMenu)

void

set_item_text(index: int, text: String)

void

set_item_text_direction(index: int, direction: TextDirection)

void

set_item_tooltip(index: int, tooltip: String)

void

toggle_item_checked(index: int)

void

toggle_item_multistate(index: int)

主題屬性

Color

font_accelerator_color

Color(0.7, 0.7, 0.7, 0.8)

Color

font_color

Color(0.875, 0.875, 0.875, 1)

Color

font_disabled_color

Color(0.4, 0.4, 0.4, 0.8)

Color

font_hover_color

Color(0.875, 0.875, 0.875, 1)

Color

font_outline_color

Color(0, 0, 0, 1)

Color

font_separator_color

Color(0.875, 0.875, 0.875, 1)

Color

font_separator_outline_color

Color(0, 0, 0, 1)

int

gutter_compact

1

int

h_separation

4

int

icon_max_width

0

int

indent

10

int

item_end_padding

2

int

item_start_padding

2

int

outline_size

0

int

search_bar_separation

4

int

separator_outline_size

0

int

v_separation

4

Font

font

Font

font_separator

int

font_separator_size

int

font_size

Texture2D

checked

Texture2D

checked_disabled

Texture2D

radio_checked

Texture2D

radio_checked_disabled

Texture2D

radio_unchecked

Texture2D

radio_unchecked_disabled

Texture2D

search

Texture2D

submenu

Texture2D

submenu_mirrored

Texture2D

unchecked

Texture2D

unchecked_disabled

StyleBox

hover

StyleBox

labeled_separator_left

StyleBox

labeled_separator_right

StyleBox

panel

StyleBox

separator


訊號

id_focused(id: int) 🔗

使用者使用 ProjectSettings.input/ui_upProjectSettings.input/ui_down 輸入動作移動至 ID 為 id 的功能表專案時發出。


id_pressed(id: int) 🔗

Emitted when an item of some id is pressed. Also emitted when its accelerator is activated on macOS.

Note: If id is negative (either explicitly or due to overflow), this will return the corresponding index instead.


index_pressed(index: int) 🔗

Emitted when an item of some index is pressed. Also emitted when its accelerator is activated on macOS.


menu_changed() 🔗

發生選單項的新增、修改、刪除時發出。


屬性說明

  • void set_allow_search(value: bool)

  • bool get_allow_search()

如果為 true,允許用字母鍵導覽 PopupMenu


bool hide_on_checkable_item_selection = true 🔗

  • void set_hide_on_checkable_item_selection(value: bool)

  • bool is_hide_on_checkable_item_selection()

如果為 true,則在選中核取方塊或選項按鈕時隱藏 PopupMenu


bool hide_on_item_selection = true 🔗

  • void set_hide_on_item_selection(value: bool)

  • bool is_hide_on_item_selection()

如果為 true,當一個專案被選中時隱藏 PopupMenu


bool hide_on_state_item_selection = false 🔗

  • void set_hide_on_state_item_selection(value: bool)

  • bool is_hide_on_state_item_selection()

如果為 true,則在選中狀態項時隱藏 PopupMenu


int item_count = 0 🔗

  • void set_item_count(value: int)

  • int get_item_count()

目前列表中的專案數。


int item_{index}/checkable = 0 🔗

The checkable item type of the item at index.

Note: index is a value in the 0 .. item_count - 1 range.


bool item_{index}/checked = false 🔗

If true, the item at index is checked.

Note: index is a value in the 0 .. item_count - 1 range.


bool item_{index}/disabled = false 🔗

If true, the item at index is disabled.

Note: index is a value in the 0 .. item_count - 1 range.


Texture2D item_{index}/icon 🔗

The icon of the item at index.

Note: index is a value in the 0 .. item_count - 1 range.


int item_{index}/id = 0 🔗

The ID of the item at index.

Note: index is a value in the 0 .. item_count - 1 range.


bool item_{index}/separator = false 🔗

If true, the item at index is a separator.

Note: index is a value in the 0 .. item_count - 1 range.


String item_{index}/text = "" 🔗

The text of the item at index.

Note: index is a value in the 0 .. item_count - 1 range.


bool prefer_native_menu = false 🔗

  • void set_prefer_native_menu(value: bool)

  • bool is_prefer_native_menu()

If true, MenuBar will use native menu when supported.

Note: If PopupMenu is linked to StatusIndicator, MenuBar, or another PopupMenu item it can use native menu regardless of this property, use is_native_menu() to check it.


bool search_bar_enabled = false 🔗

  • void set_search_bar_enabled(value: bool)

  • bool is_search_bar_enabled()

If true, shows a search bar at the top of the PopupMenu for filtering items. See search_bar_min_item_count for dynamically controlling its visibility based on the number of items.

Note: When enabled, allow_search is ignored.


bool search_bar_fuzzy_search_enabled = true 🔗

  • void set_search_bar_fuzzy_search_enabled(value: bool)

  • bool is_search_bar_fuzzy_search_enabled()

If true, enables fuzzy searching in the PopupMenu search bar. This allows the search results to include items that almost match the search query, as well items that match the individual characters of the search query, but not in sequence.

Use search_bar_fuzzy_search_max_misses to set the maximum number of mismatches allowed in the search results.


int search_bar_fuzzy_search_max_misses = 2 🔗

  • void set_search_bar_fuzzy_search_max_misses(value: int)

  • int get_search_bar_fuzzy_search_max_misses()

Sets the maximum number of mismatches allowed in each search result when fuzzy searching is enabled for the PopupMenu search bar. Any item with more mismatches will be hidden from the search results.


int search_bar_min_item_count = 0 🔗

  • void set_search_bar_min_item_count(value: int)

  • int get_search_bar_min_item_count()

Sets the minimum number of items required for the search bar to be visible. search_bar_enabled must be true for this to have any effect. Separator items are not counted.


bool shrink_height = true 🔗

  • void set_shrink_height(value: bool)

  • bool get_shrink_height()

If true, shrinks PopupMenu to minimum height when it's shown.


bool shrink_width = true 🔗

  • void set_shrink_width(value: bool)

  • bool get_shrink_width()

If true, shrinks PopupMenu to minimum width when it's shown.


float submenu_popup_delay = 0.2 🔗

  • void set_submenu_popup_delay(value: float)

  • float get_submenu_popup_delay()

Sets the delay time in seconds for the submenu item to popup on mouse hovering. If the popup menu is added as a child of another (acting as a submenu), it will inherit the delay time of the parent menu item.

Note: If the mouse is exiting a submenu item with an open submenu and enters a different submenu item, the submenu popup delay time is affected by the direction of the mouse movement toward the open submenu. If the mouse is moving toward the submenu, the open submenu will wait approximately 0.5 seconds before closing, which then allows the hovered submenu item to open. This additional delay allows the mouse time to move to the open submenu across other menu items without prematurely closing. If the mouse is not moving toward the open submenu, for example in a downward direction, the open submenu will close immediately.


SystemMenus system_menu_id = 0 🔗

If set to one of the values of SystemMenus, this PopupMenu is bound to the special system menu. Only one PopupMenu can be bound to each special menu at a time.


方法說明

bool activate_item_by_event(event: InputEvent, for_global_only: bool = false) 🔗

根據 PopupMenu 的捷徑和加速器檢查提供的 event,並啟動具有配對事件的第一個專案。如果 for_global_onlytrue,只有 global 設定為 true 的捷徑和加速器才會被呼叫。

如果專案已成功激活,則傳回 true

注意:某些Control,例如MenuButton,會自動呼叫此方法。


void add_check_item(label: String, id: int = -1, accel: Key = 0) 🔗

新增一個帶有文字 label 的新的可勾選項。

可以選擇提供一個 id 以及一個加速器(accel)。如果未提供 id,將從索引中建立一個。如果未提供 accel,則預設值 0(對應於 @GlobalScope.KEY_NONE)將被分配給該項(這意味著它不會有任何加速器)。有關加速器的更多資訊,請參閱 get_item_accelerator()

注意:可勾選的項只顯示一個勾選標記,但沒有任何內建的勾選行為,必須手動勾選/取消勾選。有關如何控制它的更多資訊,請參閱 set_item_checked()


void add_check_shortcut(shortcut: Shortcut, id: int = -1, global: bool = false) 🔗

新增一個新的可勾選項並為其分配指定的 Shortcut。將核取方塊的標籤設定為 Shortcut 的名稱。

可以選擇提供一個 id。如果未提供 id,將從索引中建立一個。

注意:可勾選項只顯示一個勾選標記,但沒有任何內建的勾選行為,必須手動勾選/取消勾選。有關如何控制它的更多資訊,請參閱 set_item_checked()


void add_icon_check_item(texture: Texture2D, label: String, id: int = -1, accel: Key = 0) 🔗

新增一個帶有文字 label 和圖示 texture 的新的可勾選項。

可以選擇提供一個 id 以及一個加速器(accel)。如果未提供 id,將從索引中建立一個。如果未提供 accel,則預設值 0(對應於 @GlobalScope.KEY_NONE)將被分配給該項(這意味著它不會有任何加速器)。有關加速器的更多資訊,請參閱 get_item_accelerator()

注意:可勾選項只顯示一個勾選標記,但沒有任何內建的勾選行為,必須手動勾選/取消勾選。有關如何控制它的更多資訊,請參閱 set_item_checked()


void add_icon_check_shortcut(texture: Texture2D, shortcut: Shortcut, id: int = -1, global: bool = false) 🔗

新增一個新的可勾選項並為其分配指定的 Shortcut 和圖示 texture。將複選框的標籤設定為 Shortcut 的名稱。

可以選擇提供一個 id。如果未提供 id,將從索引中建立一個。

注意:可勾選項只顯示一個勾選標記,但沒有任何內建的勾選行為,必須手動勾選/取消勾選。有關如何控制它的更多資訊,請參閱 set_item_checked()


void add_icon_item(texture: Texture2D, label: String, id: int = -1, accel: Key = 0) 🔗

新增帶有文字 label 和圖示 texture 的新功能表專案。

還可以提供 id 和快捷鍵(accel)。如果沒有提供 id,則會根據索引來建立。如果沒有提供 accel,則會為該功能表專案分配預設的 0(對應 @GlobalScope.KEY_NONE,在這裡表示沒有快捷鍵)。更多快捷鍵相關的信息見 get_item_accelerator()


void add_icon_radio_check_item(texture: Texture2D, label: String, id: int = -1, accel: Key = 0) 🔗

add_icon_check_item() 相同,但使用選項按鈕。


void add_icon_radio_check_shortcut(texture: Texture2D, shortcut: Shortcut, id: int = -1, global: bool = false) 🔗

add_icon_check_shortcut() 相同,但使用一個選項按鈕。


void add_icon_shortcut(texture: Texture2D, shortcut: Shortcut, id: int = -1, global: bool = false, allow_echo: bool = false) 🔗

新增新的功能表專案,並為其分配指定的 Shortcut 和圖示 texture。核取方塊的標籤會被設為 Shortcut 的名稱。

還可以提供 id。如果沒有提供 id,則會根據索引來建立。


void add_item(label: String, id: int = -1, accel: Key = 0) 🔗

新增一個帶有文字 label 的新項。

可以選擇提供一個 id 以及一個加速器(accel)。如果未提供 id,將從索引中建立一個。如果未提供 accel,則預設值 0(對應於 @GlobalScope.KEY_NONE)將被分配給該項(這意味著它不會有任何加速器)。有關加速器的更多資訊,請參閱 get_item_accelerator()

注意:提供的 id 僅用於 id_pressedid_focused 訊號。它與在函式中,例如在 set_item_checked() 中的 index 參數無關。


void add_multistate_item(label: String, max_states: int, default_state: int = 0, id: int = -1, accel: Key = 0) 🔗

Adds a new multistate item with text label.

Contrarily to normal binary items, multistate items can have more than two states, as defined by max_states. The default value is defined by default_state.

An id can optionally be provided, as well as an accelerator (accel). If no id is provided, one will be created from the index. If no accel is provided, then the default value of 0 (corresponding to @GlobalScope.KEY_NONE) will be assigned to the item (which means it won't have any accelerator). See get_item_accelerator() for more info on accelerators.

func _ready():
    add_multistate_item("Item", 3, 0)

    index_pressed.connect(func(index: int):
            toggle_item_multistate(index)
            match get_item_multistate(index):
                0:
                    print("First state")
                1:
                    print("Second state")
                2:
                    print("Third state")
        )

Note: Multistate items don't update their state automatically and must be done manually. See toggle_item_multistate(), set_item_multistate() and get_item_multistate() for more info on how to control it.


void add_radio_check_item(label: String, id: int = -1, accel: Key = 0) 🔗

新增一個帶有文字 label 的新單選勾選按鈕。

可以選擇提供一個 id 以及一個加速器(accel)。如果未提供 id,將從索引中建立一個。如果未提供 accel,則預設值 0(對應於 @GlobalScope.KEY_NONE)將被分配給該項(這意味著它不會有任何加速器)。有關加速器的更多資訊,請參閱 get_item_accelerator()

注意:可勾選項只顯示一個勾選標記,但沒有任何內建的勾選行為,必須手動勾選/取消勾選。有關如何控制它的更多資訊,請參閱 set_item_checked()


void add_radio_check_shortcut(shortcut: Shortcut, id: int = -1, global: bool = false) 🔗

新增一個新的單選勾選按鈕並為其分配一個 Shortcut。將核取方塊的標籤設定為 Shortcut 的名稱。

可以選擇提供一個 id。如果未提供 id,將從索引中建立一個。

注意:可勾選項只顯示一個勾選標記,但沒有任何內建的勾選行為,必須手動勾選/取消勾選。有關如何控制它的更多資訊,請參閱 set_item_checked()


void add_separator(label: String = "", id: int = -1) 🔗

在功能表專案之間新增分隔線。分隔線也佔用索引,可以使用 id 參數設定。

還可以提供 label,會在分隔線的中間位置顯示。


void add_shortcut(shortcut: Shortcut, id: int = -1, global: bool = false, allow_echo: bool = false) 🔗

新增 Shortcut

還可以提供 id。如果沒有提供 id,則會根據索引來建立。


void add_submenu_item(label: String, submenu: String, id: int = -1) 🔗

已棄用: Prefer using add_submenu_node_item() instead.

Adds an item that will act as a submenu of the parent PopupMenu node when clicked. The submenu argument must be the name of an existing PopupMenu that has been added as a child to this node. This submenu will be shown when the item is clicked, hovered for long enough, or activated using the ui_select or ui_right input actions.

An id can optionally be provided. If no id is provided, one will be created from the index.


void add_submenu_node_item(label: String, submenu: PopupMenu, id: int = -1) 🔗

Adds an item that will act as a submenu of the parent PopupMenu node when clicked. This submenu will be shown when the item is clicked, hovered for long enough, or activated using the ui_select or ui_right input actions.

submenu must be either child of this PopupMenu or has no parent node (in which case it will be automatically added as a child). If the submenu popup has another parent, this method will fail.

An id can optionally be provided. If no id is provided, one will be created from the index.


void clear(free_submenus: bool = false) 🔗

PopupMenu 刪除所有專案。如果 free_submenustrue,則自動釋放子選單節點。


int get_focused_item() const 🔗

返回目前焦點專案的索引。如果沒有焦點,則返回 -1


Key get_item_accelerator(index: int) const 🔗

返回給定 index 處專案的加速器。加速器是一種鍵盤快捷鍵,即使目前未打開功能表按鈕,也可以按下它來觸發功能表按鈕。返回值是一個整數,通常是 KeyModifierMaskKey 使用按位元或操作的組合,例如 KEY_MASK_CTRL | KEY_ACtrl + A)。如果沒有為指定的 index 定義加速器,則 get_item_accelerator() 返回 0(對應於 @GlobalScope.KEY_NONE)。


AutoTranslateMode get_item_auto_translate_mode(index: int) const 🔗

Returns the auto translate mode of the item at the given index.


Texture2D get_item_icon(index: int) const 🔗

返回給定 index 處功能表專案的圖示。


int get_item_icon_max_width(index: int) const 🔗

返回給定 index 處功能表專案所允許的最大圖示寬度。


Color get_item_icon_modulate(index: int) const 🔗

返回給定 index 處用於調變功能表專案圖示的 Color


int get_item_id(index: int) const 🔗

Returns the ID of the item at the given index.


int get_item_indent(index: int) const 🔗

返回給定 index 處功能表專案的水平偏移量。


int get_item_index(id: int) const 🔗

Returns the index of the item containing the specified id. The index is automatically assigned to each item by the engine when added and represents the order items will be displayed.


String get_item_language(index: int) const 🔗

返回專案文字的語言程式碼。


Variant get_item_metadata(index: int) const 🔗

返回指定功能表專案的中繼資料,可能是任何型別。可以使用 set_item_metadata() 來設定中繼資料,這樣就能很很方便地將本文資料分配給功能表專案。


int get_item_multistate(index: int) const 🔗

Returns the state of the item at the given index.


int get_item_multistate_max(index: int) const 🔗

Returns the max states of the item at the given index.


Shortcut get_item_shortcut(index: int) const 🔗

返回給定 index 處功能表專案所關聯的 Shortcut


String get_item_submenu(index: int) const 🔗

已棄用: Prefer using get_item_submenu_node() instead.

返回給定 index 處功能表專案的子功能表名稱。有關如何新增子功能表的更多資訊,請參見 add_submenu_item()


PopupMenu get_item_submenu_node(index: int) const 🔗

Returns the submenu of the item at the given index, or null if no submenu was added. See add_submenu_node_item() for more info on how to add a submenu.


String get_item_text(index: int) const 🔗

返回索引為 index 的功能表專案的文字。


TextDirection get_item_text_direction(index: int) const 🔗

返回專案文字的基礎書寫方向。


String get_item_tooltip(index: int) const 🔗

返回索引為 index 的功能表專案所關聯的工具提示。


bool is_item_checkable(index: int) const 🔗

如果給定 index 處的功能表專案可以某種方式勾選,即如果它有一個核取方塊或單選按鈕,則返回 true

注意:可勾選項僅顯示一個勾選標記或選項按鈕,但沒有任何內建的勾選行為,必須手動勾選/取消勾選。


bool is_item_checked(index: int) const 🔗

如果給定的 index 處的功能表專案被勾選,則返回 true


bool is_item_disabled(index: int) const 🔗

如果給定 index 處的功能表專案被禁用,則返回 true。功能表專案被禁用時無法被選擇,對應的動作也無法被呼叫。

有關如何禁用功能表專案的更多資訊,請參閱 set_item_disabled()


bool is_item_radio_checkable(index: int) const 🔗

如果給定 index 處的功能表專案具有選項按鈕樣式的可勾選性,則返回 true

注意:這純粹是裝飾性的;必須新增用於單選組中勾選/取消勾選專案的邏輯。


bool is_item_separator(index: int) const 🔗

如果功能表專案是分隔符號,則返回 true。分隔符號會顯示為一條線。有關如何新增分隔符號的更多資訊,請參閱 add_separator()


bool is_item_shortcut_disabled(index: int) const 🔗

如果指定功能表專案的快捷方式被禁用,則返回 true


bool is_native_menu() const 🔗

Returns true if the system native menu is supported and currently used by this PopupMenu.


bool is_system_menu() const 🔗

Returns true if the menu is bound to the special system menu.


void remove_item(index: int) 🔗

從選單中移除給定 index 處的功能表專案。

注意:被移除的功能表專案後面的功能表專案的索引將移動一位元。


void scroll_to_item(index: int) 🔗

移動滾動視圖,使位於給定 index 的功能表專案可見。


void set_focused_item(index: int) 🔗

將目前聚焦的功能表專案設定為給定的 index

-1 作為索引傳入將不會聚焦任何功能表專案。


void set_item_accelerator(index: int, accel: Key) 🔗

在給定的 index 處設定專案的加速器。加速器是一種鍵盤快捷鍵,即使目前未打開功能表按鈕,也可以按下它來觸發功能表按鈕。accel 通常是 KeyModifierMaskKey 使用按位元或操作的組合,例如 KEY_MASK_CTRL | KEY_ACtrl + A)。


void set_item_as_checkable(index: int, enable: bool) 🔗

設定給定 index 處的項是否具有一個核取方塊。如果為 false,則將項的型別設定為純文字。

注意:可勾選的項只顯示一個核取記號,但沒有任何內建的勾選行為,必須手動勾選/取消勾選。


void set_item_as_radio_checkable(index: int, enable: bool) 🔗

將給定 index 處的項的型別設定為一個選項按鈕。如果為 false,則將項的型別設定為純文字。


void set_item_as_separator(index: int, enable: bool) 🔗

將給定 index 處的項標記為分隔符號,這意味著它將顯示為直線段。如果為 false,則將項的型別設定為純文字。


void set_item_auto_translate_mode(index: int, mode: AutoTranslateMode) 🔗

Sets the auto translate mode of the item at the given index.

Items use Node.AUTO_TRANSLATE_MODE_INHERIT by default, which uses the same auto translate mode as the PopupMenu itself.


void set_item_checked(index: int, checked: bool) 🔗

設定位於給定的 index 的功能表專案的勾選狀態。


void set_item_disabled(index: int, disabled: bool) 🔗

啟用/禁用位於給定 index 的功能表專案。處於禁用狀態的功能表專案無法被選中,也無法呼叫其動作。


void set_item_icon(index: int, icon: Texture2D) 🔗

替換索引為 index 的功能表專案的 Texture2D 圖示。


void set_item_icon_max_width(index: int, width: int) 🔗

設定給定 index 處功能表專案所允許的最大圖示寬度。這是在圖示預設大小和 icon_max_width 的基礎上的限制。高度會根據圖示的長寬比調整。


void set_item_icon_modulate(index: int, modulate: Color) 🔗

設定索引為 index 的功能表專案圖示的調變 Color


void set_item_id(index: int, id: int) 🔗

設定位於給定 index 的功能表專案的 id

id_pressedid_focused 等訊號中會用到 id


void set_item_indent(index: int, indent: int) 🔗

設定索引為 index 的功能表專案的水平偏移量。


void set_item_index(index: int, target_index: int) 🔗

Changes the index of the item at index index to be at index target_index. This can be used to move an item above other items. The moved item will keep the same ID, even if it was generated from the original index.

Note: The indices of any items between index index and index target_index will be shifted by one.


void set_item_language(index: int, language: String) 🔗

Sets the language code of the text for the item at the given index to language. This is used for line-breaking and text shaping algorithms. If language is empty, the current locale is used.


void set_item_metadata(index: int, metadata: Variant) 🔗

設定項的中繼資料,該項可以是任何型別。稍後你可以使用get_item_metadata()獲取它,它提供了一種將本文資料分配給項的簡單方法。


void set_item_multistate(index: int, state: int) 🔗

設定一個多態專案的狀態。詳情請參閱 add_multistate_item()


void set_item_multistate_max(index: int, max_states: int) 🔗

Sets the max states of a multistate item. See add_multistate_item() for details.


void set_item_shortcut(index: int, shortcut: Shortcut, global: bool = false) 🔗

設定索引為 index 的功能表專案的 Shortcut


void set_item_shortcut_disabled(index: int, disabled: bool) 🔗

禁用索引為 index 的功能表專案的 Shortcut


void set_item_submenu(index: int, submenu: String) 🔗

已棄用: Prefer using set_item_submenu_node() instead.

設定位於給定 index 的功能表專案的子功能表。子功能表為點擊該功能表專案後應該顯示的子 PopupMenu 節點的名稱。


void set_item_submenu_node(index: int, submenu: PopupMenu) 🔗

Sets the submenu of the item at the given index. The submenu is a PopupMenu node that would be shown when the item is clicked. It must either be a child of this PopupMenu or has no parent (in which case it will be automatically added as a child). If the submenu popup has another parent, this method will fail.


void set_item_text(index: int, text: String) 🔗

設定索引為 index 的功能表專案的文字。


void set_item_text_direction(index: int, direction: TextDirection) 🔗

設定專案文字的基礎書寫方向。


void set_item_tooltip(index: int, tooltip: String) 🔗

設定索引為 index 的功能表專案的 String 工具提示。


void toggle_item_checked(index: int) 🔗

切換索引為 index 的功能表專案的選中狀態。


void toggle_item_multistate(index: int) 🔗

迴圈到一個多態專案的下一個狀態。詳情請參閱 add_multistate_item()


主題屬性說明

Color font_accelerator_color = Color(0.7, 0.7, 0.7, 0.8) 🔗

文字 Color 用於快捷鍵和加速器,當定義時顯示在功能表專案名稱旁邊。有關加速器的更多信息,請參閱 get_item_accelerator()


Color font_color = Color(0.875, 0.875, 0.875, 1) 🔗

功能表專案名稱的預設文字 Color


Color font_disabled_color = Color(0.4, 0.4, 0.4, 0.8) 🔗

用於禁用功能表專案的文字 Color


Color font_hover_color = Color(0.875, 0.875, 0.875, 1) 🔗

用於懸停文字的 Color


Color font_outline_color = Color(0, 0, 0, 1) 🔗

功能表專案文字輪廓的色調。


Color font_separator_color = Color(0.875, 0.875, 0.875, 1) 🔗

用於標注分隔符號文字的顏色 Color。見 add_separator()


Color font_separator_outline_color = Color(0, 0, 0, 1) 🔗

帶標籤分隔符號的文字輪廓的色調。


int gutter_compact = 1 🔗

If not 0, the icon gutter will be merged with the checkbox gutter when possible. This acts as a boolean.


int h_separation = 4 🔗

功能表專案元素之間的水平間距。


int icon_max_width = 0 🔗

功能表專案圖示所允許的最大寬度。這是在圖示預設大小的基礎上的限制,在 set_item_icon_max_width() 所設定的值之前生效。高度會根據圖示的長寬比調整。


int indent = 10 🔗

單個縮進級別的寬度。


int item_end_padding = 2 🔗

所有功能表專案右側的水平內邊距(RTL 佈局中為左側)。


int item_start_padding = 2 🔗

所有功能表專案左側的水平內邊距(RTL 佈局中為右側)。


int outline_size = 0 🔗

專案文字輪廓的大小。

注意:如果使用啟用了 FontFile.multichannel_signed_distance_field 的字形,其 FontFile.msdf_pixel_range 必須至少設定為 outline_size兩倍,輪廓算繪才能看起來正確。否則,輪廓可能會比預期的更早被切斷。


int search_bar_separation = 4 🔗

The vertical space between search bar and menu items.


int separator_outline_size = 0 🔗

帶標籤分隔符號的文字輪廓的大小。


int v_separation = 4 🔗

每個功能表專案之間的垂直間距。


Font font 🔗

用於功能表專案的 Font 字形。


Font font_separator 🔗

用於帶文字分隔線的 Font 字形。


int font_separator_size 🔗

帶標籤分隔符號的字形大小。


int font_size 🔗

功能表專案的字形大小。


Texture2D checked 🔗

Texture2D 圖示,用於處於選中狀態的複選項。


Texture2D checked_disabled 🔗

Texture2D 圖示,用於處於選中狀態的已禁用複選項。


Texture2D radio_checked 🔗

Texture2D 圖示,用於處於選中狀態的單選項。


Texture2D radio_checked_disabled 🔗

Texture2D 圖示,用於處於選中狀態的已禁用單選項。


Texture2D radio_unchecked 🔗

Texture2D 圖示,用於處於未選狀態的單選項。


Texture2D radio_unchecked_disabled 🔗

Texture2D 圖示,用於處於未選狀態的已禁用單選項。


Texture2D icon for the search bar's search icon.


Texture2D submenu 🔗

Texture2D 圖示,用於子功能表箭頭(用於從左至右佈局)。


Texture2D submenu_mirrored 🔗

Texture2D 圖示,用於子功能表箭頭(用於從右至左佈局)。


Texture2D unchecked 🔗

Texture2D 圖示,用於處於未選狀態的複選項。


Texture2D unchecked_disabled 🔗

Texture2D 圖示,用於處於未選狀態的已禁用複選項。


StyleBox hover 🔗

PopupMenu 功能表專案被懸停時顯示的 StyleBox


StyleBox labeled_separator_left 🔗

用於標籤分隔器的左側 StyleBox。請參閱 add_separator()


StyleBox labeled_separator_right 🔗

用於標籤分隔器的右側 StyleBox。請參閱 add_separator()


StyleBox panel 🔗

StyleBox for the background panel.


StyleBox separator 🔗

用於分隔符號的 StyleBox。請參閱 add_separator()