MenuButton

继承: Button < BaseButton < Control < CanvasItem < Node < Object

点击后会弹出 PopupMenu 的按钮。

描述

点击后会弹出 PopupMenu 的按钮。可以使用 get_popup().add_item("菜单项名称") 在这个 PopupMenu 中创建新的菜单项,也可以直接从 Godot 编辑器的检查器中创建。

另见 BaseButton,提供了与该节点相关的常用属性和方法。

属性

ActionMode

action_mode

0 (overrides BaseButton)

bool

flat

true (overrides Button)

FocusMode

focus_mode

0 (overrides Control)

int

item_count

0

bool

switch_on_hover

false

bool

toggle_mode

true (overrides BaseButton)

方法

PopupMenu

get_popup ( ) const

void

set_disable_shortcuts ( bool disabled )

void

show_popup ( )


信号

about_to_popup ( )

该 MenuButton 的 PopupMenu 即将显示时发出。


属性说明

int item_count = 0

  • void set_item_count ( int value )

  • int get_item_count ( )

当前列表中的项目数。


bool switch_on_hover = false

  • void set_switch_on_hover ( bool value )

  • bool is_switch_on_hover ( )

如果为 true,当光标悬停在同一父级中也启用了 switch_on_hover 的另一个 MenuButton 上方时,它将关闭当前的 MenuButton 并打开另一个。


方法说明

PopupMenu get_popup ( ) const

返回这个按钮中包含的 PopupMenu

警告:这是一个必需的内部节点,移除和释放它可能会导致崩溃。如果你想隐藏它或它的任何子节点,请使用其 Window.visible 属性。


void set_disable_shortcuts ( bool disabled )

如果为 true,快捷方式将被禁用,无法用于触发按钮。


void show_popup ( )

调整该 MenuButton 的弹出位置和大小,然后显示该 PopupMenu。请优先使用此方法,而不是使用 get_popup().popup()

Previous Next


© 版权所有 2014-present Juan Linietsky, Ariel Manzur and the Godot community (CC BY 3.0). Revision b1c660f7.

Built with Sphinx using a theme provided by Read the Docs.