Action QML 类型

Abstract user interface action. 更多...

import 语句: import QtQuick.Controls 2.5
Since: Qt 5.10
继承: QtObject

特性

信号

方法

详细描述

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 icon ,和 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 被启用 , checkable ,和 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.

另请参阅 MenuItem , ToolButton ,和 Shortcut .

特性文档编制

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.

另请参阅 checked .

checked : bool

此特性保持动作是否被复选。

另请参阅 checkable .

enabled : bool

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

icon group

icon.name : string

icon.source : url

icon.width : int

icon.height : int

icon.color : color

名称 描述
名称

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.

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 "transparent" .

shortcut : keysequence

This property holds the action's shortcut. The key sequence can be set to one of the 标准键盘快捷键 , 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 {
    shortcut: "Ctrl+E,Ctrl+W"
    onTriggered: edit.wrapMode = TextEdit.Wrap
}
																	

text : string

This property holds a textual description of the action.


信号文档编制

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.


方法文档编制

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.