Skip to content

PythonQt.Qt.QWidgetAction

QWidgetAction

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

Most actions in an application are represented as items in menus or buttons in toolbars. However sometimes more complex widgets are necessary. For example a zoom action in a word processor may be realized using a QComboBox in a QToolBar, presenting a range of different zoom levels. QToolBar provides QToolBar::insertWidget() as convenience function for inserting a single widget. However if you want to implement an action that uses custom widgets for visualization in multiple containers then you have to subclass QWidgetAction.

If a QWidgetAction is added for example to a QToolBar then QWidgetAction::createWidget() is called. Reimplementations of that function should create a new custom widget with the specified parent.

If the action is removed from a container widget then QWidgetAction::deleteWidget() is called with the previously created custom widget as argument. The default implementation hides the widget and deletes it using QObject::deleteLater().

If you have only one single custom widget then you can set it as default widget using setDefaultWidget(). That widget will then be used if the action is added to a QToolBar, or in general to an action container that supports QWidgetAction. If a QWidgetAction with only a default widget is added to two toolbars at the same time then the default widget is shown only in the first toolbar the action was added to. QWidgetAction takes over ownership of the default widget.

Note that it is up to the widget to activate the action, for example by reimplementing mouse event handlers and calling QAction::trigger().

macOS: If you add a widget to a menu in the application's menu bar on macOS, the widget will be added and it will function but with some limitations:

  1. The widget is reparented away from the QMenu to the native menu view. If you show the menu in some other place (e.g. as a popup menu), the widget will not be there.
  2. Focus/Keyboard handling of the widget is not possible.
  3. Due to Apple's design, mouse tracking on the widget currently does not work.
  4. Connecting the triggered() signal to a slot that opens a modal dialog will cause a crash in macOS 10.4 (known bug acknowledged by Apple), a workaround is to use a QueuedConnection instead of a DirectConnection.

Source: https://doc.qt.io/archives/qt-5.15/qwidgetaction.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 (shared captured text)
AboutRole attribute Any (shared captured text)
ActionEvent attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
ApplicationSpecificRole attribute Any (shared captured text)
HighPriority attribute Any (shared captured text)
Hover attribute Any (shared captured text)
LowPriority attribute Any (shared captured text)
MenuRole attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
NoRole attribute Any (shared captured text)
NormalPriority attribute Any (shared captured text)
PreferencesRole attribute Any (shared captured text)
Priority attribute type Convert a number or string to an integer, or return 0 if no arguments are given. (shared captured text)
QuitRole attribute Any (shared captured text)
TextHeuristicRole attribute Any (shared captured text)
Trigger attribute Any (shared captured text)
__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 (shared captured text)
activate function (self, event: Any) -> Any (shared captured text)
associatedGraphicsWidgets function (self) -> tuple X.associatedGraphicsWidgets() -> tuple (shared captured text)
associatedWidgets function (self) -> tuple X.associatedWidgets() -> tuple (shared captured text)
autoRepeat attribute Any (shared captured text)
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
changed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QWidgetAction.changed; argument details are not documented.
checkable attribute Any (shared captured text)
checked attribute Any (shared captured text)
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)
createWidget function (self, parent: Any) -> Any X.createWidget(parent) -> PythonQt.QtGui.QWidget (shared captured text)
createdWidgets function (self) -> tuple X.createdWidgets() -> tuple (shared captured text)
customEvent function (self, event: Any) -> Any (shared captured text)
data function (self) -> Any X.data() -> object (shared captured text)
defaultWidget function (self) -> Any X.defaultWidget() -> PythonQt.QtGui.QWidget (shared captured text)
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)
deleteWidget function (self, widget: Any) -> None This function is called whenever the action is removed from a container widget that displays the action using a custom widget previously created using… (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QWidgetAction.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 (shared captured text)
event function (self, arg__1: Any) -> bool X.event(arg__1) -> bool (shared captured text)
eventFilter function (self, arg__1: Any, arg__2: Any) -> bool X.eventFilter(arg__1, arg__2) -> 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 (shared captured text)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
hover function (self) -> Any (shared captured text)
hovered function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QWidgetAction.hovered; argument details are not documented.
icon attribute QIcon (shared captured text)
iconText attribute Any (shared captured text)
iconVisibleInMenu attribute Any (shared captured text)
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 (shared captured text)
isChecked function (self) -> bool X.isChecked() -> bool (shared captured text)
isEnabled function (self) -> bool X.isEnabled() -> bool (shared captured text)
isIconVisibleInMenu function (self) -> bool X.isIconVisibleInMenu() -> bool (shared captured text)
isSeparator function (self) -> bool X.isSeparator() -> bool (shared captured text)
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isVisible function (self) -> bool X.isVisible() -> bool (shared captured text)
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 (shared captured text)
menuRole attribute Any (shared captured text)
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.Qt.QWidgetAction.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 (shared captured text)
priority attribute Any (shared captured text)
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
releaseWidget function (self, widget: Any) -> None Releases the specified widget. (shared captured text)
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
requestWidget function (self, parent: Any) -> Any X.requestWidget(parent) -> PythonQt.QtGui.QWidget (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) -> Any (shared captured text)
setAutoRepeat function (self, arg__1: Any) -> Any (shared captured text)
setCheckable function (self, arg__1: Any) -> Any (shared captured text)
setChecked function (self, a: Any) -> Any (shared captured text)
setData function (self, var: Any) -> Any (shared captured text)
setDefaultWidget function (self, w: Any) -> None Sets widget to be the default widget. (shared captured text)
setDisabled function (self, b: Any) -> Any (shared captured text)
setEnabled function (self, a: Any) -> Any (shared captured text)
setFont function (self, font: Any) -> Any (shared captured text)
setIcon function (self, icon: Any) -> Any (shared captured text)
setIconText function (self, text: Any) -> Any (shared captured text)
setIconVisibleInMenu function (self, visible: Any) -> Any (shared captured text)
setMenu function (self, menu: Any) -> Any (shared captured text)
setMenuRole function (self, menuRole: Any) -> Any (shared captured text)
setObjectName function (self, name: Any) -> Any (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setPriority function (self, priority: Any) -> Any (shared captured text)
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setSeparator function (self, b: Any) -> Any (shared captured text)
setShortcut function (self, shortcut: Any) -> Any (shared captured text)
setShortcutContext function (self, context: Any) -> Any (shared captured text)
setShortcuts function (self, arg__1: Any) -> Any (shared captured text)
setStatusTip function (self, statusTip: Any) -> Any (shared captured text)
setText function (self, text: Any) -> Any (shared captured text)
setToolTip function (self, tip: Any) -> Any (shared captured text)
setVisible function (self, a: Any) -> Any (shared captured text)
setWhatsThis function (self, what: Any) -> Any (shared captured text)
shortcut attribute QKeySequence (shared captured text)
shortcutContext attribute Any (shared captured text)
shortcutVisibleInContextMenu attribute Any (shared captured text)
shortcuts function (self) -> tuple X.shortcuts() -> tuple (shared captured text)
showStatusText function (self, widget: Any) -> bool X.showStatusText(widget) -> bool (shared captured text)
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 Any (shared captured text)
text attribute Any (shared captured text)
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
toggle function (self) -> Any (shared captured text)
toggled function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QWidgetAction.toggled; argument details are not documented.
toolTip attribute Any (shared captured text)
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)
trigger function (self) -> Any (shared captured text)
triggered function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.Qt.QWidgetAction.triggered; argument details are not documented.
visible attribute Any (shared captured text)
whatsThis attribute Any (shared captured text)