The QAction class provides an abstract user interface action that can be inserted into widgets. 更多...
继承 QObject .
Inherited by QWidgetAction .
The QAction class provides an abstract user interface action that can be inserted into widgets.
In applications many common commands can be invoked via menus, toolbar buttons, and keyboard shortcuts. Since the user expects each command to be performed in the same way, regardless of the user interface used, it is useful to represent each command as an action .
Actions can be added to menus and toolbars, and will automatically keep them in sync. For example, in a word processor, if the user presses a Bold toolbar button, the Bold menu item will automatically be checked.
Actions can be created as independent objects, but they may also be created during the construction of menus; the QMenu class contains convenience functions for creating actions suitable for use as menu items.
A QAction may contain an icon, menu text, a shortcut, status text, "What's This?" text, and a tooltip. Most of these can be set in the constructor. They can also be set independently with setIcon (), setText (), setIconText (), setShortcut (), setStatusTip (), setWhatsThis (),和 setToolTip (). For menu items, it is possible to set an individual font with setFont ().
动作被添加到 Widget 使用 QWidget.addAction () 或 QGraphicsWidget.addAction (). Note that an action must be added to a widget before it can be used; this is also true when the shortcut should be global (i.e., Qt.ApplicationShortcut as Qt.ShortcutContext ).
Once a QAction has been created it should be added to the relevant menu and toolbar, then connected to the slot which will perform the action. For example:
openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
openAct->setShortcuts(QKeySequence.Open);
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
fileMenu->addAction(openAct);
fileToolBar->addAction(openAct);
We recommend that actions are created as children of the window they are used in. In most cases actions will be children of the application's main window.
此枚举类型会被使用,当调用 QAction.activate ()
| 常量 | 值 | 描述 |
|---|---|---|
| QAction.Trigger | 0 | 这将导致 QAction.triggered () signal to be emitted. |
| QAction.Hover | 1 | 这将导致 QAction.hovered () signal to be emitted. |
This enum describes how an action should be moved into the application menu on Mac OS X.
| 常量 | 值 | 描述 |
|---|---|---|
| QAction.NoRole | 0 | This action should not be put into the application menu |
| QAction.TextHeuristicRole | 1 | This action should be put in the application menu based on the action's text as described in the QMenuBar 文档编制。 |
| QAction.ApplicationSpecificRole | 2 | This action should be put in the application menu with an application specific role |
| QAction.AboutQtRole | 3 | This action matches handles the "About Qt" menu item. |
| QAction.AboutRole | 4 | This action should be placed where the "About" menu item is in the application menu. The text of the menu item will be set to "About <application name>". The application name is fetched from the Info.plist file in the application's bundle (See Deploying an Application on Mac OS X ). |
| QAction.PreferencesRole | 5 | This action should be placed where the "Preferences..." menu item is in the application menu. |
| QAction.QuitRole | 6 | This action should be placed where the Quit menu item is in the application menu. |
Setting this value only has effect on items that are in the immediate menus of the menubar, not the submenus of those menus. For example, if you have File menu in your menubar and the File menu has a submenu, setting the MenuRole for the actions in that submenu have no effect. They will never be moved.
此枚举定义用户界面中动作的优先级。
| 常量 | 值 | 描述 |
|---|---|---|
| QAction.LowPriority | 0 | The action should not be prioritized in the user interface. |
| QAction.NormalPriority | 128 | |
| QAction.HighPriority | 256 | The action should be prioritized in the user 接口。 |
该枚举在 Qt 4.6 引入或被修改。
另请参阅 priority .
This enum describes how an action should be placed in the softkey bar. Currently this enum only has an effect on the Symbian platform.
| 常量 | 值 | 描述 |
|---|---|---|
| QAction.NoSoftKey | 0 | This action should not be used as a softkey |
| QAction.PositiveSoftKey | 1 | This action is used to describe a softkey with a positive or non-destructive role such as Ok, Select, or Options. |
| QAction.NegativeSoftKey | 2 | This action is used to describe a soft ey with a negative or destructive role role such as Cancel, Discard, or Close. |
| QAction.SelectSoftKey | 3 | This action is used to describe a role that selects a particular item or widget in the application. |
Actions with a softkey role defined are only visible in the softkey bar when the widget containing the action has focus. If no widget currently has focus, the softkey framework will traverse up the widget parent hierarchy looking for a widget containing softkey actions.
该枚举在 Qt 4.6 引入或被修改。
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
构造动作采用 parent 。若 parent 是 action group the action will be automatically inserted into the group.
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
构造动作采用一些 text and parent 。若 parent is an action group the action will be automatically inserted into the group.
The action uses a stripped version of text (e.g. "&Menu Option..." becomes "Menu Option") as descriptive text for tool buttons. You can override this by setting a specific description with setText (). The same text will be used for tooltips unless you specify a different text using setToolTip ().
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
构造动作采用 icon 和一些 text and parent 。若 parent is an action group the action will be automatically inserted into the group.
The action uses a stripped version of text (e.g. "&Menu Option..." becomes "Menu Option") as descriptive text for tool buttons. You can override this by setting a specific description with setText (). The same text will be used for tooltips unless you specify a different text using setToolTip ().
Returns the action group for this action. If no action group manages this action then 0 will be returned.
另请参阅 QActionGroup and QAction.setActionGroup ().
发送相关信号为 ActionEvent event .
基于动作的 Widget 使用此 API 以促使 QAction to emit signals as well as emitting their own.
返回已添加此动作的小部件列表。
该函数在 Qt 4.5 引入。
另请参阅 QWidget.addAction () 和 associatedWidgets ().
返回已添加此动作的小部件列表。
该函数在 Qt 4.2 引入。
另请参阅 QWidget.addAction () 和 associatedGraphicsWidgets ().
Returns the user data as set in QAction.setData.
另请参阅 setData ().
重实现自 QObject.event ().
This method is also a Qt slot with the C++ signature void hover() .
这是调用 activate(Hover) 的方便槽。
Returns true if this action is a separator action; otherwise it returns false.
另请参阅 QAction.setSeparator ().
Returns the menu contained by this action. Actions that contain menus can be used to create menu items with submenus, or inserted into toolbars to create buttons with popup menus.
另请参阅 setMenu () 和 QMenu.addAction ().
返回父级 Widget。
把此动作组设为 group . The action will be automatically added to the group's list of actions.
组内动作将是相互排斥的。
另请参阅 QActionGroup and QAction.actionGroup ().
This method is also a Qt slot with the C++ signature void setChecked(bool) .
把动作的内部数据设为给定 userData .
另请参阅 data ().
This method is also a Qt slot with the C++ signature void setDisabled(bool) .
这是方便函数,为 enabled property, that is useful for signals--slots connections. If b is true the action is disabled; otherwise it is enabled.
This method is also a Qt slot with the C++ signature void setEnabled(bool) .
把由此动作包含的菜单设为指定 menu .
另请参阅 menu ().
若 b is true then this action will be considered a separator.
How a separator is represented depends on the widget it is inserted into. Under most circumstances the text, submenu, and icon will be ignored for separator actions.
另请参阅 QAction.isSeparator ().
集 shortcuts as the list of shortcuts that trigger the action. The first element of the list is the primary shortcut.
该函数在 Qt 4.2 引入。
另请参阅 shortcuts () and shortcut .
设置从属平台的快捷方式列表基于 key . The result of calling this function will depend on the currently running platform. Note that more than one shortcut can assigned by this action. If only the primary shortcut is required, use setShortcut instead.
该函数在 Qt 4.2 引入。
另请参阅 QKeySequence.keyBindings ().
This method is also a Qt slot with the C++ signature void setVisible(bool) .
Returns the list of shortcuts, with the primary shortcut as the first element of the list.
该函数在 Qt 4.2 引入。
另请参阅 setShortcuts ().
更新相关状态栏为 widget specified by sending a QStatusTipEvent to its parent widget. Returns true if an event was sent; otherwise returns false.
If a null widget is specified, the event is sent to the action's parent.
另请参阅 statusTip .
This method is also a Qt slot with the C++ signature void toggle() .
这是方便函数,为 checked property. Connect to it to change the checked state to its opposite state.
This method is also a Qt slot with the C++ signature void trigger() .
这是调用 activate(Trigger) 的方便槽。
This is the default overload of this signal.
This signal is emitted when an action has changed. If you are only interested in actions in a given widget, you can watch for QWidget.actionEvent () sent with an QEvent.ActionChanged .
另请参阅 QWidget.actionEvent ().
This is the default overload of this signal.
This signal is emitted when an action is highlighted by the user; for example, when the user pauses with the cursor over a menu option, toolbar button, or presses an action's shortcut key combination.
另请参阅 QAction.activate ().
This is the default overload of this signal.
此信号被发射每当可复选动作改变其 isChecked () status. This can be the result of a user interaction, or because setChecked () 被调用。
checked is true if the action is checked, or false if the action is unchecked.
另请参阅 QAction.activate (), QAction.triggered (),和 checked .
This is the default overload of this signal.
This signal is emitted when an action is activated by the user; for example, when the user clicks a menu option, toolbar button, or presses an action's shortcut key combination, or when trigger () 被调用。显而易见,它是 not 被发射当 setChecked () 或 toggle () 被调用。
若动作是可复选的, checked is true if the action is checked, or false if the action is unchecked.
另请参阅 QAction.activate (), QAction.toggled (),和 checked .