MenuItem QML Type
显示菜单中的一个项目。更多
Import Statement: | import QtQuick.Controls |
Inherits: |
属性
- arrow : Item
(since QtQuick.Controls 2.3 (Qt 5.10))
- highlighted : bool
- implicitTextPadding : real
(since 6.8)
- menu : Menu
(since QtQuick.Controls 2.3 (Qt 5.10))
- subMenu : Menu
(since QtQuick.Controls 2.3 (Qt 5.10))
- textPadding : real
(since 6.8)
信号
- void triggered()
详细说明
MenuItem 是一种实现AbstractButton API 的便利类型,提供了一种熟悉的方式来响应菜单项triggered 等。
MenuItem 继承自AbstractButton 的 API。例如,您可以使用AbstractButton API 设置text 和图标。
Button { id: fileButton text: "File" onClicked: menu.open() Menu { id: menu MenuItem { text: "New..." onTriggered: document.reset() } MenuItem { text: "Open..." onTriggered: openDialog.open() } MenuItem { text: "Save" onTriggered: saveDialog.open() } } }
属性文档
arrow : Item |
highlighted : bool |
implicitTextPadding : real |
该属性表示从contentItem 左边缘到文本所需的最小空间。它用于计算Menu 中所有 MenuItems 的公共textPadding 。
该属性在 Qt 6.8 中引入。
另请参阅 textPadding 。
menu : Menu |
该属性表示包含该菜单项的菜单,如果该菜单项不在菜单中,则表示null
。
该属性在 QtQuick.Controls 2.3 (Qt 5.10) 中引入。
subMenu : Menu |
此属性保存此项目在父菜单中显示的子菜单,如果此项目不是子菜单项,则保存null
。
该属性在 QtQuick.Controls 2.3 (Qt 5.10) 中引入。
textPadding : real |
该属性保存同一menu 中所有菜单项的最大implicitTextPadding 。
样式可以使用该属性来确保同一菜单内的所有菜单项最终与text 对齐。
一个Menu 可以由许多不同的 MenuItems 组成,有些可以选中,有些有图标,有些只包含文本。通常情况下,样式需要确保所有这些项目中的文本都左对齐(对于mirrored 项目,则右对齐)。通过让每个MenuItem 为implicitTextPadding 指定自己的最小文本填充(考虑图标和复选标记),但使用 textPadding 来实际定位text ,所有菜单项最终都应对齐。
为使其有效,所有 MenuItems 都应将implicitTextPadding 设置为从contentItem 左边缘到文本所需的最小空间。
该属性在 Qt 6.8 中引入。
另请参见 implicitTextPadding 。
信号文档
void triggered() |
该信号在用户触发菜单项时发出。
注: 相应的处理程序是onTriggered
。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.