Groups actions together. 更多...
import 语句: | import QtQuick.Controls |
继承: | QtObject |
ActionGroup is a non-visual group of actions. A mutually exclusive action group is used with actions where only one of the options can be selected at a time.
The most straight-forward way to use ActionGroup is to declare actions as children of the group.
ActionGroup { id: alignmentGroup Action { checked: true checkable: true text: qsTr("Left") } Action { checkable: true text: qsTr("Center") } Action { checkable: true text: qsTr("Right") } }
另外, group attached property allows declaring the actions elsewhere and assigning them to a specific 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 }
More advanced use cases can be handled using the
addAction()
and
removeAction()
方法。
另请参阅 动作 and ButtonGroup .
This property holds the list of actions in the group.
另请参阅 group .
checkedAction : 动作 |
This property holds the currently selected action in an exclusive group, or
null
if there is none or the group is non-exclusive.
By default, it is the first checked action added to an exclusive action group.
另请参阅 exclusive .
enabled : bool |
This property holds whether the action group is enabled. The default value is
true
.
若此特性为
false
, then all actions in the group are disabled. If this property is
true
, all actions in the group are enabled, unless explicitly disabled.
exclusive : bool |
This property holds whether the action group is exclusive. The default value is
true
.
若此特性为
true
, then only one action in the group can be checked at any given time. The user can trigger any action to check it, and that action will replace the existing one as the checked action in the group.
In an exclusive group, the user cannot uncheck the currently checked action by triggering it; instead, another action in the group must be triggered to set the new checked action for that group.
In a non-exclusive group, checking and unchecking actions does not affect the other actions in the group. Furthermore, the value of the
checkedAction
特性为
null
.
ActionGroup.group : ActionGroup |
This property attaches an action to an action group.
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 in the group has been triggered.
This signal is convenient for implementing a common signal handler for all actions in the same group.
ActionGroup { onTriggered: console.log("triggered:", action.text) Action { text: "First" } Action { text: "Second" } Action { text: "Third" } }
注意:
相应处理程序是
onTriggered
.
另请参阅 Action::triggered ().
void addAction ( 动作 action ) |
添加 action to the action group.
注意: Manually adding objects to a action group is typically unnecessary. The actions 特性和 group attached property provide a convenient and declarative syntax.
void removeAction ( 动作 action ) |
Removes an action from the action group.
注意: Manually removing objects from a action group is typically unnecessary. The actions 特性和 group attached property provide a convenient and declarative syntax.