Action QML Type
Abstract user interface action. More...
Import Statement: | import QtQuick.Controls 2.5 |
Since: | Qt 5.10 |
Inherits: |
Properties
- checkable : bool
- checked : bool
- enabled : bool
- icon
- icon.name : string
- icon.source : url
- icon.width : int
- icon.height : int
- icon.color : color
- shortcut : keysequence
- text : string
Signals
Methods
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 MenuItem, ToolButton, and Shortcut.
Property Documentation
checkable : bool |
This property holds whether the action is checkable. The default value is false
.
A checkable action toggles between checked (on) and unchecked (off) when triggered.
See also checked.
enabled : bool |
This property holds whether the action is enabled. The default value is true
.
Name | Description |
---|---|
name | This property holds the name of the icon to use. The icon will be loaded from the platform theme. If the icon is found in the theme, it will always be used; even if icon.source is also set. If the icon is not found, icon.source will be used instead. For more information on theme icons, see QIcon::fromTheme(). |
source | This property holds the name of the icon to use. The icon will be loaded as a regular image. If icon.name is set and refers to a valid theme icon, it will always be used instead of this property. |
width | This property holds the width of the icon. The icon's width will never exceed this value, though it will shrink when necessary. |
height | This property holds the height of the icon. The icon's height will never exceed this value, though it will shrink when necessary. |
color | This property holds the color of the icon. The icon is tinted with the specified color, unless the color is set to |
This property holds the action's shortcut. The key sequence can be set to one of the standard keyboard shortcuts, or it can be described with a string containing a sequence of up to four key presses that are needed to trigger the shortcut.
Action { sequence: "Ctrl+E,Ctrl+W" onTriggered: edit.wrapMode = TextEdit.Wrap }
text : string |
This property holds a textual description of the action.
Signal Documentation
toggled(QtObject source) |
This signal is emitted when the action is toggled. The source argument identifies the object that toggled the action.
For example, if the action is assigned to a menu item and a toolbar button, the action is toggled when the control is toggled, the shortcut is activated, or when toggle() is called directly.
triggered(QtObject source) |
This signal is emitted when the action is triggered. The source argument identifies the object that triggered the action.
For example, if the action is assigned to a menu item and a toolbar button, the action is triggered when the control is clicked, the shortcut is activated, or when trigger() is called directly.
Method Documentation
void toggle(QtObject source = null) |
Toggles the action and emits toggled() if enabled, with an optional source object defined.
void trigger(QtObject source = null) |
Triggers the action and emits triggered() if enabled, with an optional source object defined.
© 2019 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.