Action QML Type▲
-
Import Statement: import QtQuick.Controls 2.5
-
Since: Qt 5.10
-
Inherits: QtObject
-
Group: Action is part of utilities
Detailed Description▲
Action represents an abstract user interface action that can have shortcuts and can be assigned to menu items and toolbar buttons.
Actions may contain text, an icon, and a shortcut. Actions are normally triggered by the user via menu items, toolbar buttons, or keyboard shortcuts. A checkable Action toggles its checked state when triggered.
Action
{
id
:
copyAction
text
:
qsTr("&Copy"
)
icon.name
:
"edit-copy"
shortcut
:
StandardKey.Copy
onTriggered
:
window.activeFocusItem.copy()
}
Action is commonly used to implement application commands that can be invoked via menu items, toolbar buttons, and keyboard shortcuts. Since the user expects the commands to be performed in the same way, regardless of the user interface used, it is useful to represent the commands as shareable actions.
Action can be also used to separate the logic and the visual presentation. For example, when declaring buttons and menu items in .ui.qml files, actions can be declared elsewhere and assigned from the outside.
ToolButton
{
id
:
toolButton
action
:
copyAction
}
When an action is paired with buttons and menu items, the enabled, checkable, and checked states are synced automatically. For example, in a word processor, if the user clicks a "Bold" toolbar button, the "Bold" menu item will automatically be checked. Buttons and menu items get their text and icon from the action by default. An action-specific text or icon can be overridden for a specific control by specifying text or icon directly on the control.
MenuItem
{
id
:
menuItem
action
:
copyAction
text
:
qsTr("&Copy selected Text"
)
}
Since Action presents a user interface action, it is intended to be assigned to a MenuItem, ToolButton, or any other control that inherits AbstractButton. For keyboard shortcuts, the simpler Shortcut type is more appropriate.
See Also▲
See also MenuItem, ToolButton, Shortcut