内容表

上一话题

QAccessibleWidget

下一话题

QActionGroup

QAction

QAction class provides an abstract user interface action that can be inserted into widgets. 更多

Inheritance diagram of PySide2.QtWidgets.QAction

继承者: QWidgetAction

概要

信号

详细描述

在应用程序中,许多常见命令可以凭借菜单、工具栏按钮及键盘快捷键援引。由于用户期望每个命令以相同方式履行,不管所用用户界面,它是有用的将每个命令表示成 action .

动作可以被添加到菜单和工具栏,并自动保持同步。例如,在单词处理程序中,若用户按下加粗工具栏按钮,加粗菜单项将被自动选中。

可以将动作创建成独立对象,但也可以在构造菜单期间创建; QMenu 类包含用于创建适合用作菜单项的动作的方便函数。

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 使用 addAction() or 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., ApplicationShortcut as ShortcutContext ).

一旦 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 = QAction(QIcon(":/images/open.png"), tr("&Open..."), self)
openAct.setShortcuts(QKeySequence.Open)
openAct.setStatusTip(tr("Open an existing file"))
openAct.triggered.connect(open)
											

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.

class QAction ( [ parent=None ] )

QAction(icon, text[, parent=None])

QAction(text[, parent=None])

param parent

QObject

param icon

QIcon

param text

unicode

构造动作采用 parent 。若 parent 是动作组,动作会被自动插入组中。

注意

parent 自变量是可选的,从 Qt 5.7 起。

构造动作采用 icon 和一些 text and parent 。若 parent 是动作组,动作会被自动插入组中。

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

PySide2.QtWidgets.QAction. MenuRole

此枚举描述应该如何把动作移入 macOS 应用程序菜单。

常量

描述

QAction.NoRole

此动作不应放入应用程序菜单中

QAction.TextHeuristicRole

This action should be put in the application menu based on the action’s text as described in the QMenuBar 文档编制。

QAction.ApplicationSpecificRole

This action should be put in the application menu with an application specific role

QAction.AboutQtRole

This action handles the “About Qt” menu item.

QAction.AboutRole

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 Qt for macOS - Deployment).

QAction.PreferencesRole

This action should be placed where the “Preferences…” menu item is in the application menu.

QAction.QuitRole

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 for the actions in that submenu have no effect. They will never be moved.

PySide2.QtWidgets.QAction. Priority

此枚举定义用户界面中动作的优先级。

常量

描述

QAction.LowPriority

动作不应该在用户界面中被优先。

QAction.NormalPriority

QAction.HighPriority

动作应该在用户界面中被优先。

另请参阅

priority

4.6 版新增。

PySide2.QtWidgets.QAction. ActionEvent

使用此枚举类型当调用 activate()

常量

描述

QAction.Trigger

这将导致 triggered() signal to be emitted.

QAction.Hover

这将导致 hovered() signal to be emitted.

PySide2.QtWidgets.QAction. actionGroup ( )
返回类型

QActionGroup

返回此动作的动作组。返回 0 若没有动作组管理此动作。

另请参阅

QActionGroup setActionGroup()

PySide2.QtWidgets.QAction. activate ( event )
参数

event ActionEvent

发送相关信号为 ActionEvent event .

基于动作的 Widget 使用此 API 以促使 QAction 去发射信号及发射它们自己。

PySide2.QtWidgets.QAction. associatedGraphicsWidgets ( )
返回类型

返回已添加此动作的小部件列表。

另请参阅

addAction() associatedWidgets()

PySide2.QtWidgets.QAction. associatedWidgets ( )
返回类型

返回已添加此动作的小部件列表。

另请参阅

addAction() associatedGraphicsWidgets()

PySide2.QtWidgets.QAction. autoRepeat ( )
返回类型

bool

另请参阅

setAutoRepeat()

PySide2.QtWidgets.QAction. changed ( )
PySide2.QtWidgets.QAction. data ( )
返回类型

object

返回用户设置数据在 setData .

另请参阅

setData()

PySide2.QtWidgets.QAction. font ( )
返回类型

QFont

另请参阅

setFont()

PySide2.QtWidgets.QAction. hover ( )

这是调用 activate(Hover) 的方便槽。

PySide2.QtWidgets.QAction. hovered ( )
PySide2.QtWidgets.QAction. icon ( )
返回类型

QIcon

另请参阅

setIcon()

PySide2.QtWidgets.QAction. iconText ( )
返回类型

unicode

另请参阅

setIconText()

PySide2.QtWidgets.QAction. isCheckable ( )
返回类型

bool

PySide2.QtWidgets.QAction. isChecked ( )
返回类型

bool

PySide2.QtWidgets.QAction. isEnabled ( )
返回类型

bool

PySide2.QtWidgets.QAction. isIconVisibleInMenu ( )
返回类型

bool

PySide2.QtWidgets.QAction. isSeparator ( )
返回类型

bool

返回 true 若此动作是分隔符动作;否则它返回 false .

另请参阅

setSeparator()

PySide2.QtWidgets.QAction. isShortcutVisibleInContextMenu ( )
返回类型

bool

PySide2.QtWidgets.QAction. isVisible ( )
返回类型

bool

PySide2.QtWidgets.QAction. menu ( )
返回类型

QMenu

返回由此动作包含的菜单。包含菜单的动作可以被用于创建带子菜单的菜单项,或被插入工具栏中以创建带弹出菜单的按钮。

另请参阅

setMenu() addAction()

PySide2.QtWidgets.QAction. menuRole ( )
返回类型

MenuRole

另请参阅

setMenuRole()

PySide2.QtWidgets.QAction. parentWidget ( )
返回类型

QWidget

返回父级 Widget。

PySide2.QtWidgets.QAction. priority ( )
返回类型

Priority

另请参阅

setPriority()

PySide2.QtWidgets.QAction. setActionGroup ( group )
参数

group QActionGroup

把此动作组设为 group . The action will be automatically added to the group’s list of actions.

组内动作将是相互排斥的。

另请参阅

QActionGroup actionGroup()

PySide2.QtWidgets.QAction. setAutoRepeat ( arg__1 )
参数

arg__1 bool

另请参阅

autoRepeat()

PySide2.QtWidgets.QAction. setCheckable ( arg__1 )
参数

arg__1 bool

另请参阅

isCheckable()

PySide2.QtWidgets.QAction. setChecked ( arg__1 )
参数

arg__1 bool

另请参阅

isChecked()

PySide2.QtWidgets.QAction. setData ( var )
参数

var – object

Sets the action’s internal data to the given userData .

另请参阅

data()

PySide2.QtWidgets.QAction. setDisabled ( b )
参数

b bool

这是方便函数,为 enabled property, that is useful for signals–slots connections. If b is true the action is disabled; otherwise it is enabled.

PySide2.QtWidgets.QAction. setEnabled ( arg__1 )
参数

arg__1 bool

另请参阅

isEnabled()

PySide2.QtWidgets.QAction. setFont ( font )
参数

font QFont

另请参阅

font()

PySide2.QtWidgets.QAction. setIcon ( icon )
参数

icon QIcon

另请参阅

icon()

PySide2.QtWidgets.QAction. setIconText ( text )
参数

text – unicode

另请参阅

iconText()

PySide2.QtWidgets.QAction. setIconVisibleInMenu ( visible )
参数

visible bool

另请参阅

isIconVisibleInMenu()

PySide2.QtWidgets.QAction. setMenu ( menu )
参数

menu QMenu

把由此动作包含的菜单设为指定 menu .

另请参阅

menu()

PySide2.QtWidgets.QAction. setMenuRole ( menuRole )
参数

menuRole MenuRole

另请参阅

menuRole()

PySide2.QtWidgets.QAction. setPriority ( priority )
参数

priority Priority

另请参阅

priority()

PySide2.QtWidgets.QAction. setSeparator ( b )
参数

b bool

b 为 true,则此动作将被认为是分隔符。

如何表示分隔符从属插入其的 Widget。在大多数情况下,文本、子菜单及图标会被分隔符动作忽略。

另请参阅

isSeparator()

PySide2.QtWidgets.QAction. setShortcut ( shortcut )
参数

shortcut QKeySequence

另请参阅

shortcut()

PySide2.QtWidgets.QAction. setShortcutContext ( context )
参数

context ShortcutContext

另请参阅

shortcutContext()

PySide2.QtWidgets.QAction. setShortcutVisibleInContextMenu ( show )
参数

show bool

另请参阅

isShortcutVisibleInContextMenu()

PySide2.QtWidgets.QAction. setShortcuts ( arg__1 )
参数

arg__1 StandardKey

设置从属平台的快捷方式列表基于 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 代替。

另请参阅

keyBindings()

PySide2.QtWidgets.QAction. setShortcuts ( shortcuts )
参数

shortcuts

PySide2.QtWidgets.QAction. setStatusTip ( statusTip )
参数

statusTip – unicode

另请参阅

statusTip()

PySide2.QtWidgets.QAction. setText ( text )
参数

text – unicode

另请参阅

text()

PySide2.QtWidgets.QAction. setToolTip ( tip )
参数

tip – unicode

另请参阅

toolTip()

PySide2.QtWidgets.QAction. setVisible ( arg__1 )
参数

arg__1 bool

另请参阅

isVisible()

PySide2.QtWidgets.QAction. setWhatsThis ( what )
参数

what – unicode

另请参阅

whatsThis()

PySide2.QtWidgets.QAction. shortcut ( )
返回类型

QKeySequence

返回首要快捷键。

另请参阅

setShortcuts()

PySide2.QtWidgets.QAction. shortcutContext ( )
返回类型

ShortcutContext

另请参阅

setShortcutContext()

PySide2.QtWidgets.QAction. shortcuts ( )
返回类型

返回快捷键列表,采用首要快捷键作为列表的第一元素。

另请参阅

setShortcuts()

PySide2.QtWidgets.QAction. showStatusText ( [ widget=None ] )
参数

widget QWidget

返回类型

bool

更新相关状态栏为 widget 指定通过发送 QStatusTipEvent 到其父级 Widget。返回 true 若事件被发送;否则返回 false .

If a null widget is specified, the event is sent to the action’s parent.

另请参阅

statusTip

PySide2.QtWidgets.QAction. statusTip ( )
返回类型

unicode

另请参阅

setStatusTip()

PySide2.QtWidgets.QAction. text ( )
返回类型

unicode

另请参阅

setText()

PySide2.QtWidgets.QAction. toggle ( )

这是方便函数,为 checked property. Connect to it to change the checked state to its opposite state.

PySide2.QtWidgets.QAction. toggled ( arg__1 )
参数

arg__1 bool

PySide2.QtWidgets.QAction. toolTip ( )
返回类型

unicode

另请参阅

setToolTip()

PySide2.QtWidgets.QAction. trigger ( )

这是调用 activate(Trigger) 的方便槽。

PySide2.QtWidgets.QAction. triggered ( [ checked=false ] )
参数

checked bool

PySide2.QtWidgets.QAction. whatsThis ( )
返回类型

unicode

另请参阅

setWhatsThis()