Skip to content

PythonQt.QtGui.QAction

QAction

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

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(), and setToolTip(). For menu items, it is possible to set an individual font with setFont().

Actions are added to widgets using QWidget::addAction() or 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:

    const QIcon openIcon = QIcon::fromTheme("document-open", QIcon(":/images/open.png"));
    QAction *openAct = new QAction(openIcon, tr("&Open..."), this);
    openAct->setShortcuts(QKeySequence::Open);
    openAct->setStatusTip(tr("Open an existing file"));
    connect(openAct, &QAction::triggered, this, &MainWindow::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.

Source: https://doc.qt.io/archives/qt-5.15/qaction.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
AboutQtRole attribute Any
AboutRole attribute Any
ActionEvent attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
ApplicationSpecificRole attribute Any
HighPriority attribute Any (shared captured text)
Hover attribute Any
LowPriority attribute Any
MenuRole attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
NoRole attribute Any
NormalPriority attribute Any (shared captured text)
PreferencesRole attribute Any
Priority attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
QuitRole attribute Any
TextHeuristicRole attribute Any
Trigger attribute Any
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
actionGroup function (self) -> Any X.actionGroup() -> PythonQt.QtGui.QActionGroup
activate function (self, event: Any) -> None Sends the relevant signals for [ActionEvent](https://doc.qt.io/archives/qt-5.15/qaction.html#ActionEvent-enum) event.
associatedGraphicsWidgets function (self) -> tuple X.associatedGraphicsWidgets() -> tuple
associatedWidgets function (self) -> tuple X.associatedWidgets() -> tuple
autoRepeat attribute bool This property holds whether the action can auto repeat
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
changed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QAction.changed; argument details are not documented.
checkable attribute Any This property holds whether the action is a checkable action
checked attribute Any This property holds whether the action is checked.
childEvent function (self, event: Any) -> Any (shared captured text)
children function (self) -> tuple X.children() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
connect function (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool X.connect(signal, receiver, slot, type) -> bool (shared captured text)
customEvent function (self, event: Any) -> Any (shared captured text)
data function (self) -> Any X.data() -> object
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
deleteLater function (self) -> Any (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QAction.destroyed; argument details are not documented.
disconnect function (self, signal: Any, receiver: Any, slot: Any) -> bool X.disconnect(signal, receiver, slot) -> bool (shared captured text)
dumpObjectInfo function (self) -> Any (shared captured text)
dumpObjectTree function (self) -> Any (shared captured text)
dynamicPropertyNames function (self) -> Any (shared captured text)
enabled attribute Any This property holds whether the action is enabled
event function (self, arg__1: Any) -> bool X.event(arg__1) -> bool
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
findChild function (self, type: Any, name: Any) -> Any X.findChild(type, name) -> PythonQt.private.QObject (shared captured text)
findChildren function (self, type: Any, name: Any) -> tuple X.findChildren(type, name) -> tuple (shared captured text)
font attribute QFont This property holds the action's font
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
hover function (self) -> None This is a convenience slot that calls activate(Hover).
hovered function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QAction.hovered; argument details are not documented.
icon attribute QIcon This property holds the action's icon
iconText attribute str This property holds the action's descriptive icon text
iconVisibleInMenu attribute Any This property holds whether or not an action should show an icon in a menu
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
isCheckable function (self) -> bool X.isCheckable() -> bool
isChecked function (self) -> bool X.isChecked() -> bool
isEnabled function (self) -> bool X.isEnabled() -> bool
isIconVisibleInMenu function (self) -> bool X.isIconVisibleInMenu() -> bool
isSeparator function (self) -> bool X.isSeparator() -> bool
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isVisible function (self) -> bool X.isVisible() -> bool
isWidgetType function (self) -> bool X.isWidgetType() -> bool (shared captured text)
isWindowType function (self) -> bool X.isWindowType() -> bool (shared captured text)
killTimer function (self, id: Any) -> Any (shared captured text)
menu function (self) -> Any X.menu() -> PythonQt.QtGui.QMenu
menuRole attribute Any This property holds the action's menu role
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
moveToThread function (self, thread: Any) -> Any (shared captured text)
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QAction.objectNameChanged; argument details are not documented.
parent function (self) -> Any X.parent() -> PythonQt.private.QObject (shared captured text)
parentWidget function (self) -> Any X.parentWidget() -> PythonQt.QtGui.QWidget
priority attribute Any This property holds the actions's priority in the user interface.
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
sender function (self) -> Any X.sender() -> PythonQt.private.QObject (shared captured text)
senderSignalIndex function (self) -> int X.senderSignalIndex() -> int (shared captured text)
setActionGroup function (self, group: Any) -> None Sets this action group to group.
setAutoRepeat function (self, arg__1: bool) -> None
setCheckable function (self, arg__1: bool) -> None
setChecked function (self, a: Any) -> None
setData function (self, var: Any) -> None Sets the action's internal data to the given userData.
setDisabled function (self, b: bool) -> None This is a convenience function for the [enabled](https://doc.qt.io/archives/qt-5.15/qaction.html#enabled-prop) property, that is useful for signals--slots connections.
setEnabled function (self, a: Any) -> None
setFont function (self, font: Any) -> None
setIcon function (self, icon: Any) -> None
setIconText function (self, text: str) -> None
setIconVisibleInMenu function (self, visible: bool) -> None
setMenu function (self, menu: Any) -> None Sets the menu contained by this action to the specified menu.
setMenuRole function (self, menuRole: Any) -> None
setObjectName function (self, name: Any) -> Any (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setPriority function (self, priority: Any) -> None
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setSeparator function (self, b: bool) -> None If b is true then this action will be considered a separator.
setShortcut function (self, shortcut: Any) -> None
setShortcutContext function (self, context: Any) -> None
setShortcuts function (self, arg__1: Any) -> None Sets shortcuts as the list of shortcuts that trigger the action.
setStatusTip function (self, statusTip: str) -> None
setText function (self, text: str) -> None
setToolTip function (self, tip: str) -> None
setVisible function (self, a: Any) -> None
setWhatsThis function (self, what: str) -> None
shortcut attribute QKeySequence This property holds the action's primary shortcut key
shortcutContext attribute Any This property holds the context for the action's shortcut
shortcutVisibleInContextMenu attribute Any This property holds whether or not an action should show a shortcut in a context menu
shortcuts function (self) -> tuple X.shortcuts() -> tuple
showStatusText function (self, widget: Any) -> bool X.showStatusText(widget) -> bool
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
statusTip attribute str This property holds the action's status tip
text attribute str This property holds the action's descriptive text
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
toggle function (self) -> None This is a convenience function for the [checked](https://doc.qt.io/archives/qt-5.15/qaction.html#checked-prop) property.
toggled function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QAction.toggled; argument details are not documented.
toolTip attribute str This property holds the action's tooltip
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)
trigger function (self) -> None This is a convenience slot that calls activate(Trigger).
triggered function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QAction.triggered; argument details are not documented.
visible attribute Any This property holds whether the action can be seen (e.g. in menus and toolbars)
whatsThis attribute str This property holds the action's "What's This?" help text