Inherited by: QWidgetAction
The PySide.QtGui.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 PySide.QtGui.QMenu class contains convenience functions for creating actions suitable for use as menu items.
A PySide.QtGui.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 PySide.QtGui.QAction.setIcon() , PySide.QtGui.QAction.setText() , PySide.QtGui.QAction.setIconText() , PySide.QtGui.QAction.setShortcut() , PySide.QtGui.QAction.setStatusTip() , PySide.QtGui.QAction.setWhatsThis() , and PySide.QtGui.QAction.setToolTip() . For menu items, it is possible to set an individual font with PySide.QtGui.QAction.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 PySide.QtGui.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")) connect(openAct, SIGNAL("triggered()"), self, 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.
See also
PySide.QtGui.QMenu PySide.QtGui.QToolBar Application Example
Parameters: |
|
---|
Constructs an action with parent . If parent is an action group the action will be automatically inserted into the group.
Constructs an action with an icon and some text and parent . If 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 PySide.QtGui.QAction.setText() . The same text will be used for tooltips unless you specify a different text using PySide.QtGui.QAction.setToolTip() .
Constructs an action with some text and parent . If 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 PySide.QtGui.QAction.setText() . The same text will be used for tooltips unless you specify a different text using PySide.QtGui.QAction.setToolTip() .
This enum defines priorities for actions in user interface.
Constant | Description |
---|---|
QAction.LowPriority | The action should not be prioritized in the user interface. |
QAction.NormalPriority | |
QAction.HighPriority | The action should be prioritized in the user interface. |
See also
Note
This enum was introduced or modified in Qt 4.6
This enum type is used when calling QAction.activate()
Constant | Description |
---|---|
QAction.Trigger | this will cause the QAction.triggered() signal to be emitted. |
QAction.Hover | this will cause the QAction.hovered() signal to be emitted. |
This enum describes how an action should be placed in the softkey bar. Currently this enum only has an effect on the Symbian platform.
Constant | Description |
---|---|
QAction.NoSoftKey | This action should not be used as a softkey |
QAction.PositiveSoftKey | This action is used to describe a softkey with a positive or non-destructive role such as Ok, Select, or Options. |
QAction.NegativeSoftKey | This action is used to describe a soft ey with a negative or destructive role role such as Cancel, Discard, or Close. |
QAction.SelectSoftKey | 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.
Note
This enum was introduced or modified in Qt 4.6
This enum describes how an action should be moved into the application menu on Mac OS X.
Constant | Description |
---|---|
QAction.NoRole | This action should not be put into the application menu |
QAction.TextHeuristicRole | This action should be put in the application menu based on the action’s text as described in the PySide.QtGui.QMenuBar documentation. |
QAction.ApplicationSpecificRole | This action should be put in the application menu with an application specific role |
QAction.AboutQtRole | This action matches 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 Deploying an Application on Mac OS X ). |
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 QAction.MenuRole for the actions in that submenu have no effect. They will never be moved.
Return type: | PySide.QtGui.QActionGroup |
---|
Returns the action group for this action. If no action group manages this action then 0 will be returned.
Parameters: | event – PySide.QtGui.QAction.ActionEvent |
---|
Sends the relevant signals for QAction.ActionEvent event .
Action based widgets use this API to cause the PySide.QtGui.QAction to emit signals as well as emitting their own.
Return type: |
---|
Returns a list of widgets this action has been added to.
Return type: |
---|
Returns a list of widgets this action has been added to.
Return type: | PySide.QtCore.bool |
---|
This property holds whether the action can auto repeat.
If true, the action will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.
Return type: | object |
---|
Returns the user data as set in QAction::setData.
See also
Return type: | PySide.QtGui.QFont |
---|
This property holds the action’s font.
The font property is used to render the text set on the PySide.QtGui.QAction . The font will can be considered a hint as it will not be consulted in all cases based upon application and style.
By default, this property contains the application’s default font.
See also
This is a convenience slot that calls activate(Hover).
Return type: | PySide.QtGui.QIcon |
---|
This property holds the action’s icon.
In toolbars, the icon is used as the tool button icon; in menus, it is displayed to the left of the menu text. There is no default icon.
On Symbian the icons which are passed to softkeys, i.e. to actions with softkey role, need to have pixmap alpha channel correctly set otherwise drawing artifacts will appear when softkey is pressed down.
If a null icon ( QIcon.isNull() is passed into this function, the icon of the action is cleared.
Return type: | unicode |
---|
This property holds the action’s descriptive icon text.
If QToolBar.toolButtonStyle is set to a value that permits text to be displayed, the text defined held in this property appears as a label in the relevant tool button.
It also serves as the default text in menus and tooltips if the action has not been defined with PySide.QtGui.QAction.setText() or PySide.QtGui.QAction.setToolTip() , and will also be used in toolbar buttons if no icon has been defined using PySide.QtGui.QAction.setIcon() .
If the icon text is not explicitly set, the action’s normal text will be used for the icon text.
By default, this property contains an empty string.
Return type: | PySide.QtCore.bool |
---|
This property holds whether the action is a checkable action.
A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is false.
In some situations, the state of one toggle action should depend on the state of others. For example, “Left Align”, “Center” and “Right Align” toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a PySide.QtGui.QActionGroup with the QActionGroup.exclusive property set to true.
See also
Return type: | PySide.QtCore.bool |
---|
This property holds whether the action is checked..
Only checkable actions can be checked. By default, this is false (the action is unchecked).
See also
checkable()
Return type: | PySide.QtCore.bool |
---|
This property holds whether the action is enabled.
Disabled actions cannot be chosen by the user. They do not disappear from menus or toolbars, but they are displayed in a way which indicates that they are unavailable. For example, they might be displayed using only shades of gray.
What’s This? help on disabled actions is still available, provided that the QAction.whatsThis property is set.
An action will be disabled when all widgets to which it is added (with QWidget.addAction() ) are disabled or not visible. When an action is disabled, it is not possible to trigger it through its shortcut.
By default, this property is true (actions are enabled).
See also
Return type: | PySide.QtCore.bool |
---|
This property holds Whether or not an action should show an icon in a menu.
In some applications, it may make sense to have actions with icons in the toolbar, but not in menus. If true, the icon (if valid) is shown in the menu, when it is false, it is not shown.
The default is to follow whether the Qt.AA_DontShowIconsInMenus attribute is set for the application. Explicitly settings this property overrides the presence (or abscence) of the attribute.
For example:
app = QApplication(argv)
app.setAttribute(Qt.AA_DontShowIconsInMenus) # Icons are *no longer shown* in menus
// ...
myAction = QAction()
// ...
myAction.setIcon(SomeIcon)
myAction.setIconVisibleInMenu(True) # Icon *will* be shown in menus for *this* action.
See also
QAction.icon QApplication.setAttribute()
Return type: | PySide.QtCore.bool |
---|
Returns true if this action is a separator action; otherwise it returns false.
See also
Return type: | PySide.QtCore.bool |
---|
This property holds whether the action can be seen (e.g. in menus and toolbars).
If visible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; if visible is false the action cannot be seen or chosen by the user.
Actions which are not visible are not grayed out; they do not appear at all.
By default, this property is true (actions are visible).
Return type: | PySide.QtGui.QMenu |
---|
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.
Return type: | PySide.QtGui.QAction.MenuRole |
---|
This property holds the action’s menu role.
This indicates what role the action serves in the application menu on Mac OS X. By default all action have the TextHeuristicRole , which means that the action is added based on its text (see PySide.QtGui.QMenuBar for more information).
The menu role can only be changed before the actions are put into the menu bar in Mac OS X (usually just before the first application window is shown).
Return type: | PySide.QtGui.QWidget |
---|
Returns the parent widget.
Return type: | PySide.QtGui.QAction.Priority |
---|
This property holds the actions’s priority in the user interface..
This property can be set to indicate how the action should be prioritized in the user interface.
For instance, when toolbars have the Qt.ToolButtonTextBesideIcon mode set, then actions with LowPriority will not show the text labels.
Parameters: | group – PySide.QtGui.QActionGroup |
---|
Sets this action group to group . The action will be automatically added to the group’s list of actions.
Actions within the group will be mutually exclusive.
Parameters: | arg__1 – PySide.QtCore.bool |
---|
This property holds whether the action can auto repeat.
If true, the action will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.
Parameters: | arg__1 – PySide.QtCore.bool |
---|
This property holds whether the action is a checkable action.
A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is false.
In some situations, the state of one toggle action should depend on the state of others. For example, “Left Align”, “Center” and “Right Align” toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a PySide.QtGui.QActionGroup with the QActionGroup.exclusive property set to true.
See also
Parameters: | arg__1 – PySide.QtCore.bool |
---|
This property holds whether the action is checked..
Only checkable actions can be checked. By default, this is false (the action is unchecked).
See also
checkable()
Parameters: | var – object |
---|
Sets the action’s internal data to the given userData .
See also
Parameters: | b – PySide.QtCore.bool |
---|
This is a convenience function for the enabled() property, that is useful for signals–slots connections. If b is true the action is disabled; otherwise it is enabled.
Parameters: | arg__1 – PySide.QtCore.bool |
---|
This property holds whether the action is enabled.
Disabled actions cannot be chosen by the user. They do not disappear from menus or toolbars, but they are displayed in a way which indicates that they are unavailable. For example, they might be displayed using only shades of gray.
What’s This? help on disabled actions is still available, provided that the QAction.whatsThis property is set.
An action will be disabled when all widgets to which it is added (with QWidget.addAction() ) are disabled or not visible. When an action is disabled, it is not possible to trigger it through its shortcut.
By default, this property is true (actions are enabled).
See also
Parameters: | font – PySide.QtGui.QFont |
---|
This property holds the action’s font.
The font property is used to render the text set on the PySide.QtGui.QAction . The font will can be considered a hint as it will not be consulted in all cases based upon application and style.
By default, this property contains the application’s default font.
See also
Parameters: | icon – PySide.QtGui.QIcon |
---|
This property holds the action’s icon.
In toolbars, the icon is used as the tool button icon; in menus, it is displayed to the left of the menu text. There is no default icon.
On Symbian the icons which are passed to softkeys, i.e. to actions with softkey role, need to have pixmap alpha channel correctly set otherwise drawing artifacts will appear when softkey is pressed down.
If a null icon ( QIcon.isNull() is passed into this function, the icon of the action is cleared.
Parameters: | text – unicode |
---|
This property holds the action’s descriptive icon text.
If QToolBar.toolButtonStyle is set to a value that permits text to be displayed, the text defined held in this property appears as a label in the relevant tool button.
It also serves as the default text in menus and tooltips if the action has not been defined with PySide.QtGui.QAction.setText() or PySide.QtGui.QAction.setToolTip() , and will also be used in toolbar buttons if no icon has been defined using PySide.QtGui.QAction.setIcon() .
If the icon text is not explicitly set, the action’s normal text will be used for the icon text.
By default, this property contains an empty string.
Parameters: | visible – PySide.QtCore.bool |
---|
This property holds Whether or not an action should show an icon in a menu.
In some applications, it may make sense to have actions with icons in the toolbar, but not in menus. If true, the icon (if valid) is shown in the menu, when it is false, it is not shown.
The default is to follow whether the Qt.AA_DontShowIconsInMenus attribute is set for the application. Explicitly settings this property overrides the presence (or abscence) of the attribute.
For example:
app = QApplication(argv)
app.setAttribute(Qt.AA_DontShowIconsInMenus) # Icons are *no longer shown* in menus
// ...
myAction = QAction()
// ...
myAction.setIcon(SomeIcon)
myAction.setIconVisibleInMenu(True) # Icon *will* be shown in menus for *this* action.
See also
QAction.icon QApplication.setAttribute()
Parameters: | menu – PySide.QtGui.QMenu |
---|
Sets the menu contained by this action to the specified menu .
See also
Parameters: | menuRole – PySide.QtGui.QAction.MenuRole |
---|
This property holds the action’s menu role.
This indicates what role the action serves in the application menu on Mac OS X. By default all action have the TextHeuristicRole , which means that the action is added based on its text (see PySide.QtGui.QMenuBar for more information).
The menu role can only be changed before the actions are put into the menu bar in Mac OS X (usually just before the first application window is shown).
Parameters: | priority – PySide.QtGui.QAction.Priority |
---|
This property holds the actions’s priority in the user interface..
This property can be set to indicate how the action should be prioritized in the user interface.
For instance, when toolbars have the Qt.ToolButtonTextBesideIcon mode set, then actions with LowPriority will not show the text labels.
Parameters: | b – PySide.QtCore.bool |
---|
If 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.
See also
Parameters: | shortcut – PySide.QtGui.QKeySequence |
---|
This property holds the action’s primary shortcut key.
Valid keycodes for this property can be found in Qt.Key and Qt.Modifier . There is no default shortcut key.
Parameters: | context – PySide.QtCore.Qt.ShortcutContext |
---|
This property holds the context for the action’s shortcut.
Valid values for this property can be found in Qt.ShortcutContext . The default value is Qt.WindowShortcut .
Parameters: | arg__1 – PySide.QtGui.QKeySequence.StandardKey |
---|
Parameters: | shortcuts – |
---|
Parameters: | softKeyRole – PySide.QtGui.QAction.SoftKeyRole |
---|
This property holds the action’s softkey role.
This indicates what type of role this action describes in the softkey framework on platforms where such a framework is supported. Currently this is only supported on the Symbian platform.
The softkey role can be changed any time.
Parameters: | statusTip – unicode |
---|
This property holds the action’s status tip.
The status tip is displayed on all status bars provided by the action’s top-level parent widget.
By default, this property contains an empty string.
Parameters: | text – unicode |
---|
This property holds the action’s descriptive text.
If the action is added to a menu, the menu option will consist of the icon (if there is one), the text, and the shortcut (if there is one). If the text is not explicitly set in the constructor, or by using PySide.QtGui.QAction.setText() , the action’s description icon text will be used as text. There is no default text.
See also
Parameters: | tip – unicode |
---|
This property holds the action’s tooltip.
This text is used for the tooltip. If no tooltip is specified, the action’s text is used.
By default, this property contains the action’s text.
Parameters: | arg__1 – PySide.QtCore.bool |
---|
This property holds whether the action can be seen (e.g. in menus and toolbars).
If visible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; if visible is false the action cannot be seen or chosen by the user.
Actions which are not visible are not grayed out; they do not appear at all.
By default, this property is true (actions are visible).
Parameters: | what – unicode |
---|
This property holds the action’s “What’s This?” help text.
The “What’s This?” text is used to provide a brief description of the action. The text may contain rich text. There is no default “What’s This?” text.
See also
PySide.QtGui.QWhatsThis Q3StyleSheet
Return type: | PySide.QtGui.QKeySequence |
---|
This property holds the action’s primary shortcut key.
Valid keycodes for this property can be found in Qt.Key and Qt.Modifier . There is no default shortcut key.
Return type: | PySide.QtCore.Qt.ShortcutContext |
---|
This property holds the context for the action’s shortcut.
Valid values for this property can be found in Qt.ShortcutContext . The default value is Qt.WindowShortcut .
Return type: |
---|
Returns the list of shortcuts, with the primary shortcut as the first element of the list.
See also
Parameters: | widget – PySide.QtGui.QWidget |
---|---|
Return type: | PySide.QtCore.bool |
Updates the relevant status bar for the widget specified by sending a PySide.QtGui.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.
See also
Return type: | PySide.QtGui.QAction.SoftKeyRole |
---|
This property holds the action’s softkey role.
This indicates what type of role this action describes in the softkey framework on platforms where such a framework is supported. Currently this is only supported on the Symbian platform.
The softkey role can be changed any time.
Return type: | unicode |
---|
This property holds the action’s status tip.
The status tip is displayed on all status bars provided by the action’s top-level parent widget.
By default, this property contains an empty string.
Return type: | unicode |
---|
This property holds the action’s descriptive text.
If the action is added to a menu, the menu option will consist of the icon (if there is one), the text, and the shortcut (if there is one). If the text is not explicitly set in the constructor, or by using PySide.QtGui.QAction.setText() , the action’s description icon text will be used as text. There is no default text.
See also
This is a convenience function for the checked() property. Connect to it to change the checked state to its opposite state.
Parameters: | arg__1 – PySide.QtCore.bool |
---|
Return type: | unicode |
---|
This property holds the action’s tooltip.
This text is used for the tooltip. If no tooltip is specified, the action’s text is used.
By default, this property contains the action’s text.
This is a convenience slot that calls activate(Trigger).
Parameters: | checked – PySide.QtCore.bool |
---|
Return type: | unicode |
---|
This property holds the action’s “What’s This?” help text.
The “What’s This?” text is used to provide a brief description of the action. The text may contain rich text. There is no default “What’s This?” text.
See also
PySide.QtGui.QWhatsThis Q3StyleSheet