ActionGroup QML Type

将行动分组。更多

Import Statement: import QtQuick.Controls
Inherits:

QtObject

属性

附属物业

信号

方法

详细说明

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() 方法可以处理更高级的用例。

另请参阅 ActionButtonGroup

属性文档

actions : list<Action> [default]

该属性包含组中的操作列表。

另请参阅 group


checkedAction : Action

该属性保存当前在排他性组中选择的操作,如果没有该操作或该组是非排他性的,则保存null

默认情况下,它是添加到排他性动作组中的第一个被选中的动作。

另请参阅 exclusive


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)

action 添加到动作组。

注: 通常不需要手动添加对象到动作组。actions 属性和group 附加属性提供了方便的声明式语法。

另请参阅 actionsgroup


void removeAction(Action action)

从动作组中删除action

注: 通常没有必要手动从动作组中删除对象。actions 属性和group 附加属性提供了方便的声明式语法。

另请参阅 actionsgroup


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