MenuItemGroup QML Type
用于管理本地菜单项的组。更多
Import Statement: | import Qt.labs.platform |
Inherits: |
属性
- checkedItem : MenuItem
- enabled : bool
- exclusive : bool
- items : list<MenuItem>
- visible : bool
信号
方法
- void addItem(MenuItem item)
- void clear()
- void removeItem(MenuItem item)
详细说明
MenuItemGroup 将本地菜单项分组。
默认情况下,MenuItemGroup 是排他性的。在排他性菜单项组中,任何时候都只能选中一个项目;选中另一个项目会自动取消选中之前选中的项目。MenuItemGroup 可以配置为非排他性,这对于显示、隐藏、启用和禁用作为一组的项目特别有用。
使用 MenuItemGroup 的最直接方法是指定一个项目列表。
Menu { id: verticalMenu title: qsTr("Vertical") MenuItemGroup { id: verticalGroup items: verticalMenu.items } MenuItem { text: qsTr("Top"); checkable: true } MenuItem { text: qsTr("Center"); checked: true } MenuItem { text: qsTr("Bottom"); checkable: true } }
同一菜单有时可能包含不应包含在同一排他性组中的项目。这种情况最好使用group 属性来处理。
Menu { id: horizontalMenu title: qsTr("Horizontal") MenuItemGroup { id: horizontalGroup } MenuItem { checked: true text: qsTr("Left") group: horizontalGroup } MenuItem { checkable: true text: qsTr("Center") group: horizontalGroup } MenuItem { text: qsTr("Right") checkable: true group: horizontalGroup } MenuItem { separator: true } MenuItem { text: qsTr("Justify"); checkable: true } MenuItem { text: qsTr("Absolute"); checkable: true } }
更高级的用例可使用addItem() 和removeItem() 方法处理。
注意: Qt.labs 模块中的类型不保证在未来版本中保持兼容。
另请参阅 MenuItem 。
属性文档
checkedItem : MenuItem |
该属性表示组中当前选中的项目,如果没有选中项目,则表示null
。
enabled : bool |
该属性显示组是否启用。默认值为true
。
组的启用状态会影响组中每个项目的启用状态,但即使组已启用,显式禁用的项目也不会启用。
exclusive : bool |
该属性表示组是否为排他性组。默认值是true
。
在排他性菜单项组中,任何时候都只能选中一个项目;选中另一个项目会自动取消选中之前选中的项目。
visible : bool |
该属性显示组是否可见。默认值为true
。
组的可见性会影响组中每个项目的可见性,但明确隐藏的项目即使组可见也不可见。
信号文档
hovered(MenuItem item) |
triggered(MenuItem item) |
方法文档
void addItem(MenuItem item) |
向组添加item 。
void clear() |
删除组中的所有项目。
void removeItem(MenuItem item) |
从组中删除item 。
© 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.