QActionGroup¶
The
QActionGroup
class groups actions together. More…
Synopsis¶
Functions¶
def
actions
()def
addAction
(a)def
addAction
(icon, text)def
addAction
(text)def
checkedAction
()def
exclusionPolicy
()def
isEnabled
()def
isExclusive
()def
isVisible
()def
removeAction
(a)
Slots¶
def
setDisabled
(b)def
setEnabled
(arg__1)def
setExclusionPolicy
(policy)def
setExclusive
(arg__1)def
setVisible
(arg__1)
Signals¶
Detailed Description¶
In some situations it is useful to group
QAction
objects together. For example, if you have a Left Align action, a Right Align action, a Justify action, and a Center action, only one of these actions should be active at any one time. One simple way of achieving this is to group the actions together in an action group.Here’s a example (from the Menus example):
alignmentGroup = QActionGroup(self) alignmentGroup.addAction(leftAlignAct) alignmentGroup.addAction(rightAlignAct) alignmentGroup.addAction(justifyAct) alignmentGroup.addAction(centerAct) leftAlignAct.setChecked(True)Here we create a new action group. Since the action group is exclusive by default, only one of the actions in the group is checked at any one time.
A
QActionGroup
emits antriggered()
signal when one of its actions is chosen. Each action in an action group emits itstriggered()
signal as usual.As stated above, an action group is exclusive by default; it ensures that at most only one checkable action is active at any one time. If you want to group checkable actions without making them exclusive, you can turn off exclusiveness by calling
setExclusive
(false).By default the active action of an exclusive group cannot be unchecked. In some cases it may be useful to allow unchecking all the actions, you can allow this by calling
setExclusionPolicy
(QActionGroup::ExclusionPolicy::ExclusiveOptional).Actions can be added to an action group using
addAction()
, but it is usually more convenient to specify a group when creating actions; this ensures that actions are automatically created with a parent. Actions can be visually separated from each other by adding a separator action to the group; create an action and useQAction
‘ssetSeparator()
function to make it considered a separator. Action groups are added to widgets with theaddActions()
function.See also
- class PySide2.QtWidgets.QActionGroup(parent)¶
- param parent:
Constructs an action group for the
parent
object.The action group is exclusive by default. Call
setExclusive
(false) to make the action group non-exclusive. To make the group exclusive but allow unchecking the active action call insteadsetExclusionPolicy
(QActionGroup::ExclusionPolicy::ExclusiveOptional)
- PySide2.QtWidgets.QActionGroup.ExclusionPolicy¶
This enum specifies the different policies that can be used to control how the group performs exclusive checking on checkable actions.
Constant
Description
QActionGroup.ExclusionPolicy.None
The actions in the group can be checked independently of each other.
QActionGroup.ExclusionPolicy.Exclusive
Exactly one action can be checked at any one time. This is the default policy.
QActionGroup.ExclusionPolicy.ExclusiveOptional
At most one action can be checked at any one time. The actions can also be all unchecked.
See also
New in version 5.14.
- PySide2.QtWidgets.QActionGroup.actions()¶
- Return type:
Returns the list of this groups’s actions. This may be empty.
- PySide2.QtWidgets.QActionGroup.addAction(icon, text)¶
- Parameters:
icon –
PySide2.QtGui.QIcon
text – str
- Return type:
Creates and returns an action with
text
and anicon
. The newly created action is a child of this action group.Normally an action is added to a group by creating it with the group as its parent, so this function is not usually used.
See also
setActionGroup()
- PySide2.QtWidgets.QActionGroup.addAction(a)
- Parameters:
- Return type:
Adds the
action
to this group, and returns it.Normally an action is added to a group by creating it with the group as its parent, so this function is not usually used.
See also
setActionGroup()
- PySide2.QtWidgets.QActionGroup.addAction(text)
- Parameters:
text – str
- Return type:
- PySide2.QtWidgets.QActionGroup.checkedAction()¶
- Return type:
Returns the currently checked action in the group, or
None
if none are checked.
- PySide2.QtWidgets.QActionGroup.exclusionPolicy()¶
- Return type:
This property holds This property holds the group exclusive checking policy.
If is set to Exclusive, only one checkable action in the action group can ever be active at any time. If the user chooses another checkable action in the group, the one they chose becomes active and the one that was active becomes inactive. If is set to ExclusionOptional the group is exclusive but the active checkable action in the group can be unchecked leaving the group with no actions checked.
See also
checkable
- PySide2.QtWidgets.QActionGroup.hovered(arg__1)¶
- Parameters:
arg__1 –
PySide2.QtWidgets.QAction
- PySide2.QtWidgets.QActionGroup.isEnabled()¶
- Return type:
bool
This property holds whether the action group is enabled.
Each action in the group will be enabled or disabled unless it has been explicitly disabled.
See also
setEnabled()
- PySide2.QtWidgets.QActionGroup.isExclusive()¶
- Return type:
bool
Returns true if the group is exclusive
The group is exclusive if the
ExclusionPolicy
is either Exclusive or ExclusionOptional.
- PySide2.QtWidgets.QActionGroup.isVisible()¶
- Return type:
bool
This property holds whether the action group is visible.
Each action in the action group will match the visible state of this group unless it has been explicitly hidden.
See also
setEnabled()
- PySide2.QtWidgets.QActionGroup.removeAction(a)¶
- Parameters:
Removes the
action
from this group. The action will have no parent as a result.See also
setActionGroup()
- PySide2.QtWidgets.QActionGroup.setDisabled(b)¶
- Parameters:
b – bool
This is a convenience function for the
enabled
property, that is useful for signals–slots connections. Ifb
is true the action group is disabled; otherwise it is enabled.
- PySide2.QtWidgets.QActionGroup.setEnabled(arg__1)¶
- Parameters:
arg__1 – bool
This property holds whether the action group is enabled.
Each action in the group will be enabled or disabled unless it has been explicitly disabled.
See also
setEnabled()
- PySide2.QtWidgets.QActionGroup.setExclusionPolicy(policy)¶
- Parameters:
policy –
ExclusionPolicy
This property holds This property holds the group exclusive checking policy.
If is set to Exclusive, only one checkable action in the action group can ever be active at any time. If the user chooses another checkable action in the group, the one they chose becomes active and the one that was active becomes inactive. If is set to ExclusionOptional the group is exclusive but the active checkable action in the group can be unchecked leaving the group with no actions checked.
See also
checkable
- PySide2.QtWidgets.QActionGroup.setExclusive(arg__1)¶
- Parameters:
arg__1 – bool
Enable or disable the group exclusion checking
This is a convenience method that calls
setExclusionPolicy
(ExclusionPolicy::Exclusive) whenb
is true, elsesetExclusionPolicy
(QActionGroup::ExclusionPolicy::None).See also
- PySide2.QtWidgets.QActionGroup.setVisible(arg__1)¶
- Parameters:
arg__1 – bool
This property holds whether the action group is visible.
Each action in the action group will match the visible state of this group unless it has been explicitly hidden.
See also
setEnabled()
- PySide2.QtWidgets.QActionGroup.triggered(arg__1)¶
- Parameters:
arg__1 –
PySide2.QtWidgets.QAction
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.