Action QML Type

Action提供了可以绑定到项目更多...的抽象用户界面操作

Import Statement: import QtQuick.Controls 1.4

Properties

Signals

Methods

Detailed Description

在应用程序中,可以通过菜单,工具栏按钮和键盘快捷键调用许多常用命令。由于用户期望每个命令都以相同的方式执行,无论使用的用户界面如何,将每个命令表示为action非常有用。

一个动作可以绑定到一个菜单项和一个工具栏按钮,并且它会自动保持它们同步。例如,在文字处理器中,如果用户按下粗体工具栏按钮,则会自动检查粗体菜单项。

QtQuick控件支持ButtonToolButtonMenuItem中的动作。


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

checkable : bool

菜单项是否可以被检查或切换。Defaults to false.

See also checked and exclusiveGroup.


checked : bool

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.


enabled : bool

行动是否被启用,并且可以被触发。Defaults to true.

See also trigger() and triggered.


exclusiveGroup : ExclusiveGroup

如果某个操作是可检查的,则可以附加一个ExclusiveGroup共享相同排他组的所有动作都是互斥排列的,这意味着只有最后一次检查的动作才会被检查。

Defaults to null, meaning no exclusive behavior is to be expected.

See also checkable and checked.


iconName : string

设置操作的图标名称。这将从当前主题中选择具有给定名称的图标。

Defaults to the empty string.


iconSource : url

设置操作的图标文件或资源url。默认为空的URL。


shortcut : keysequence

快捷方式绑定到该操作。keysequence可以是一个字符串或标准键

缺省为空字符串。


  Action {
      id: copyAction
      text: qsTr("&Copy")
      shortcut: StandardKey.Copy
  }


text : string

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.


tooltip : string

当悬停绑定到此操作的控件时,将显示工具提示。并非所有的控件都支持所有平台上的工具提示,特别是MenuItem

缺省为空字符串。


Signal Documentation

toggled(checked)

每当动作的检查属性发生变化时发出。这通常发生在触发的同一时间。

相应的处理程序是onToggled


triggered(QObject *source)

当菜单项或其绑定动作被激活时发射。包括触发相关事件的对象(例如Button或MenuItem)。您不需要发出此信号,而是使用trigger()

相应的处理程序是onTriggered


Method Documentation

void trigger(QObject *source)

如果动作已启用,将发出triggered信号。如果Action可以从知道触发的起源(例如分析)中获益,则可以提供源对象。如果可检查,也会发出切换信号。