ActionGroup QML Type

Groups actions together. More...

Import Statement: import QtQuick.Controls 2.14
Since: Qt 5.10
Inherits:

QtObject

Properties

Attached Properties

Signals

Methods

Detailed Description

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")
    }
}

Alternatively, the 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() methods.

See also Action and ButtonGroup.

Property Documentation

[default] actions : list<Action>

This property holds the list of actions in the group.

See also 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.

See also exclusive.


enabled : bool

This property holds whether the action group is enabled. The default value is true.

If this property is 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.

If this property is 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 property is null.


Attached Property Documentation

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
}

See also actions.


Signal Documentation

triggered(action)

This signal is emitted when an 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" }
}

See also Action::triggered().


Method Documentation

void addAction(action)

Adds an action to the action group.

Note: Manually adding objects to a action group is typically unnecessary. The actions property and the group attached property provide a convenient and declarative syntax.

See also actions and group.


void removeAction(action)

Removes an action from the action group.

Note: Manually removing objects from a action group is typically unnecessary. The actions property and the group attached property provide a convenient and declarative syntax.

See also actions and group.


© 2020 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.