Groups actions together. 更多...
导入语句: | import QtQuick.Controls 2.2 |
Since: | Qt 5.10 |
继承: | 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()
方法。
另请参阅 Action and ButtonGroup .
[default] actions : list < Action > |
This property holds the list of actions in the group.
另请参阅 group .
checkedAction : Action |
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 ) |
此信号被发射当 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 ) |
添加 action to the action group.
注意: Manually adding objects to a action group is typically unnecessary. The actions property and the group attached property provide a convenient and declarative syntax.
void removeAction ( Action action ) |
Removes an action from the action group.
注意: Manually removing objects from a action group is typically unnecessary. The actions property and the group attached property provide a convenient and declarative syntax.