Action QML Type
Action提供了可以绑定到项目更多...的抽象用户界面操作
Import Statement: | import QtQuick.Controls 1.4 |
Properties
- checkable : bool
- checked : bool
- enabled : bool
- exclusiveGroup : ExclusiveGroup
- iconName : string
- iconSource : url
- shortcut : keysequence
- text : string
- tooltip : string
Signals
Methods
- void trigger(QObject *source)
Detailed Description
在应用程序中,可以通过菜单,工具栏按钮和键盘快捷键调用许多常用命令。由于用户期望每个命令都以相同的方式执行,无论使用的用户界面如何,将每个命令表示为action非常有用。
一个动作可以绑定到一个菜单项和一个工具栏按钮,并且它会自动保持它们同步。例如,在文字处理器中,如果用户按下粗体工具栏按钮,则会自动检查粗体菜单项。
QtQuick控件支持Button,ToolButton和MenuItem中的动作。
... Action { id: copyAction text: "&Copy" shortcut: StandardKey.Copy iconName: "edit-copy" enabled: (!!activeFocusItem && !!activeFocusItem["copy"]) onTriggered: activeFocusItem.copy() } Action { id: cutAction text: "Cu&t" shortcut: StandardKey.Cut iconName: "edit-cut" enabled: (!!activeFocusItem && !!activeFocusItem["cut"]) onTriggered: activeFocusItem.cut() } Action { id: pasteAction text: "&Paste" shortcut: StandardKey.Paste iconName: "edit-paste" enabled: (!!activeFocusItem && !!activeFocusItem["paste"]) onTriggered: activeFocusItem.paste() } toolBar: ToolBar { RowLayout { anchors.fill: parent anchors.margins: spacing Label { text: UI.label } Item { Layout.fillWidth: true } CheckBox { id: enabler text: "Enabled" checked: true } } } menuBar: MenuBar { Menu { title: "&File" MenuItem { text: "E&xit" shortcut: StandardKey.Quit onTriggered: Qt.quit() } } Menu { title: "&Edit" visible: tabView.currentIndex == 2 MenuItem { action: cutAction } MenuItem { action: copyAction } MenuItem { action: pasteAction } } Menu { title: "&Help" MenuItem { text: "About..." onTriggered: aboutDialog.open() } } } ...
Property Documentation
菜单项是否可以被检查或切换。Defaults to false
.
See also checked and exclusiveGroup.
If the action is checkable, this property reflects its checked state. Defaults to false
. Its value is also false while checkable is false.
See also toggled and exclusiveGroup.
exclusiveGroup : ExclusiveGroup |
如果某个操作是可检查的,则可以附加一个ExclusiveGroup。共享相同排他组的所有动作都是互斥排列的,这意味着只有最后一次检查的动作才会被检查。
Defaults to null
, meaning no exclusive behavior is to be expected.
iconSource : url |
设置操作的图标文件或资源url。默认为空的URL。
Text for the action. This text will show as the button text, or as title in a menu item.
Mnemonics are supported by prefixing the shortcut letter with &. For instance, "\&Open"
will bind the Alt-O
shortcut to the "Open"
menu item. Note that not all platforms support mnemonics.
Defaults to the empty string.
当悬停绑定到此操作的控件时,将显示工具提示。并非所有的控件都支持所有平台上的工具提示,特别是MenuItem。
缺省为空字符串。