ActionData QML Type

A declarative action with a configurable shortcut. More...

Import Statement: import org.kde.kirigamiaddons.actions
In C++: QAction

Properties

Detailed Description

This element needs to always be declared as a child of ActionCollection. It is the declarative representation of a named action within the application with a user-configurable shortcut.

This element can be assigned to one or more ActionContext objects through the contexts property. An inactive context disables and hides the action by default. When multiple contexts are active, activeContext refers to the active context with the highest priority.

KirigamiActions.ActionContext {
    id: documentContext
    active: pageStack.currentItem === editorPage
}
KirigamiActions.ActionData {
    name: "save"
    contexts: documentContext
}

The regular QAction properties, such as text, toolTip, enabled, checkable and checked, can be assigned directly in QML. Its name must be unique within the containing collection.

The action is registered with the AbstractKirigamiApplication when its collection is complete. It is therefore available to the command bar and its shortcut can be configured by the user in the standard shortcut editor.

import org.kde.kirigamiaddons.actions as KirigamiActions

KirigamiActions.StatefulWindow {
    id: root
    application: MyApplication {}

    KirigamiActions.ActionCollection {
        application: root.application
        name: "document"
        text: i18n("Document Actions")

        KirigamiActions.ActionData {
            name: "document_save"
            text: i18n("Save")
            toolTip: i18n("Save the current document")
            icon.name: "document-save"
            defaultShortcut: "Ctrl+S"
            onTriggered: document.save()
        }
    }
}

See also ActionCollection and StandardActionData.

Property Documentation

action : QtQuick.Controls::Action

This property holds the QML Action this ActionData is associated to, if any. Since ActionData is just a description of an action, in order to be an active working action it has to be associated with a QML Action instance, preferably a Kirigami.Action specialization.

It can be associated either here by binding this property to the id of an Action instance or from the Action instance using the ActionCollection attached property.

Direct example:

KirigamiActions.ActionCollection {
    application: root.application
    KirigamiActions.ActionData {
        name: "copy"
        icon.name: "edit-copy"
        text: i18n("Copy")
        action: copyAction
    }
}

Kirigami.Action {
    id: copyAction
    onTriggered: document.copy()
}

Attached property example:

KirigamiActions.ActionCollection {
    application: root.application
    name: "EditActions"
    KirigamiActions.ActionData {
        name: "copy"
        icon.name: "edit-copy"
        text: i18n("Copy")
    }
}

Kirigami.Action {
    KirigamiActions.ActionCollection.collection: "EditActions"
    KirigamiActions.ActionCollection.action: "copy"
    onTriggered: document.copy()
}

actionGroup : ActionGroup

The optional group used to make related actions mutually exclusive.

Set checkable to true on the grouped actions. The group can be declared as a sibling of the actions in an ActionCollection.

KirigamiActions.ActionGroup {
    id: modes
    exclusive: true
}
KirigamiActions.ActionData {
    name: "mode_one"
    checkable: true
    actionGroup: modes
}

activeContext : ActionContext

The highest-priority active context, or null when no context is active.

contextActive : bool

Whether at least one of this action's contexts is active.

contextEnabled : bool

Whether an inactive context disables this action. Defaults to true.

contextVisible : bool

Whether an inactive context hides this action. Defaults to true.

contexts : list<ActionContext>

The contexts that control this action.

data : var

Additional data associated with the action.

defaultAlternateShortcut : keysequence

The alternate shortcut assigned when no user-configured shortcut exists.

defaultShortcut : keysequence

The shortcut assigned when no user-configured shortcut exists.

The value can be a string containing one or more key presses, such as "Ctrl+E,Ctrl+W", or a Qt standard key sequence. The user's configured shortcut takes precedence over this value.

ActionData {
    name: "close_document"
    defaultShortcut: "Ctrl+W"
}

icon group

icon.cache : bool

icon.color : color

icon.height : real

icon.name : string

icon.source : string

icon.width : real

Description for the icon to use, which can be specified by name or path.

name : string

The unique name of the action within its collection. It should be set only once.