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 。
属性文档
actions : list<Action> [default]
该属性包含该组中的操作列表。
另请参阅 group 。
checkedAction : Action
该属性存储排他性操作组中当前选中的操作;如果该组不存在或为非排他性操作组,则该属性值为null 。
默认情况下,它是添加到排他性操作组中的第一个已选中操作。
另请参阅 ` exclusive`。
enabled : bool
该属性用于指定操作组是否已启用。默认值为true 。
如果该属性值为false ,则该组中的所有操作均被禁用。如果该属性值为true ,则该组中的所有操作均被启用,除非被明确禁用。
exclusive : bool
该属性用于指定操作组是否为排他性组。默认值为true 。
如果此属性为true ,则在任何给定时刻,该组中只能有一个操作被选中。用户可以触发任何操作来选中它,该操作将取代现有操作,成为该组中被选中的操作。
在排他性组中,用户无法通过触发当前已选中的操作来取消其选中状态;相反,必须触发该组中的另一个操作,才能为该组设置新的已选中操作。
在非排他性组中,选中或取消选中某个操作不会影响组中的其他操作。此外,checkedAction 属性的值为null 。
附加属性文档
ActionGroup.group : ActionGroup [attached]
此属性将一个操作附加到一个操作组上。
ActionGroup { id: group }
Action {
checked: true
text: qsTr("Option A")
ActionGroup.group: group
}
Action {
text: qsTr("Option B")
ActionGroup.group: group
}另请参阅 actions 。
Signal 文档
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)
将一个action 添加到操作组中。
void removeAction(Action action)
从操作组中移除一个action 。
© 2026 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.