ActionGroup QML Type
将行动分组。更多
Import Statement: | import QtQuick.Controls |
Inherits: |
属性
- actions : list<Action>
- checkedAction : Action
- enabled : bool
- exclusive : bool
附属物业
- group : ActionGroup
信号
- triggered(Action action)
方法
- void addAction(Action action)
- void removeAction(Action action)
详细说明
ActionGroup 是一个非可视的操作组。互为exclusive 的操作组用于一次只能选择其中一个选项的操作。
使用 ActionGroup 的最直接方法是将操作声明为组的子操作。
ActionGroup { id: alignmentGroup Action { checked: true checkable: true text: qsTr("Left") } Action { checkable: true text: qsTr("Center") } Action { checkable: true text: qsTr("Right") } }
另外,group 附加属性允许在其他地方声明操作,并将其分配给特定组。
ActionGroup { id: alignmentGroup } Action { checked: true checkable: true text: qsTr("Left") ActionGroup.group: alignmentGroup } Action { checkable: true text: qsTr("Center") ActionGroup.group: alignmentGroup } Action { checkable: true text: qsTr("Right") ActionGroup.group: alignmentGroup }
使用addAction()
和removeAction()
方法可以处理更高级的用例。
另请参阅 Action 和ButtonGroup 。
属性文档
checkedAction : Action |
enabled : bool |
该属性用于保存动作组是否已启用。默认值为true
。
如果该属性为false
,则组中的所有操作都被禁用。如果此属性为true
,除非明确禁用,否则组中的所有操作都将启用。
exclusive : bool |
该属性表示动作组是否具有排他性。默认值为true
。
如果该属性为true
,则任何时候都只能检查组中的一个操作。用户可以触发任何动作对其进行检查,该动作将取代现有动作,成为组中被检查的动作。
在排他性组中,用户不能通过触发当前已选中的操作来取消选中;相反,必须触发组中的另一个操作来为该组设置新的已选中操作。
在非排他性组中,选中和取消选中操作不会影响组中的其他操作。此外,checkedAction 属性的值是null
。
附加属性文档
ActionGroup.group : ActionGroup |
该属性将一个操作附加到一个操作组。
ActionGroup { id: group } Action { checked: true text: qsTr("Option A") ActionGroup.group: group } Action { text: qsTr("Option B") ActionGroup.group: group }
另请参阅 actions 。
信号 文档
triggered(Action action) |
该信号在组中的action 被触发时发出。
该信号便于为同组中的所有操作实现通用信号处理器。
ActionGroup { onTriggered: console.log("triggered:", action.text) Action { text: "First" } Action { text: "Second" } Action { text: "Third" } }
注: 相应的处理程序是onTriggered
。
另请参阅 Action::triggered() 。
方法文档
void addAction(Action action) |
void removeAction(Action action) |
© 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.