- Qt 6.5
- Qt GUI
- C++ Classes
- QActionGroup
- Qt 6.5.0 Reference Documentation

# QActionGroup Class

The QActionGroup class groups actions together. More...

Header: | #include <QActionGroup>
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: | QT += gui
Since: | Qt 6.0
Inherits: | QObject

- List of all members, including inherited members

## Public Types

enum class | ExclusionPolicy { None, Exclusive, ExclusiveOptional }

## Properties

- enabled : bool
- exclusionPolicy : QActionGroup::ExclusionPolicy
- visible : bool

## Public Functions

| QActionGroup(QObject *parent)
virtual | ~QActionGroup()
QList<QAction *> | actions() const
QAction * | addAction(QAction *action)
QAction * | addAction(const QString &text)
QAction * | addAction(const QIcon &icon, const QString &text)
QAction * | checkedAction() const
QActionGroup::ExclusionPolicy | exclusionPolicy() const
bool | isEnabled() const
bool | isExclusive() const
bool | isVisible() const
void | removeAction(QAction *action)

## Public Slots

void | setDisabled(bool b)
void | setEnabled(bool)
void | setExclusionPolicy(QActionGroup::ExclusionPolicy policy)
void | setExclusive(bool b)
void | setVisible(bool)

## Detailed Description

QActionGroup is a base class for classes grouping classes inhheriting QAction objects together.

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, inheriting QActionGroup.

See also QAction.

## Member Type Documentation

### enum class QActionGroup::ExclusionPolicy

This enum specifies the different policies that can be used to control how the group performs exclusive checking on checkable actions.

Constant | Value | Description
--- | --- | ---
`QActionGroup::ExclusionPolicy::None` | `0` | The actions in the group can be checked independently of each other.
`QActionGroup::ExclusionPolicy::Exclusive` | `1` | Exactly one action can be checked at any one time. This is the default policy.
`QActionGroup::ExclusionPolicy::ExclusiveOptional` | `2` | At most one action can be checked at any one time. The actions can also be all unchecked.

See also exclusionPolicy.

## Property Documentation

### enabled : 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.

Access functions:

bool | isEnabled() const
void | setEnabled(bool)

See also QAction::setEnabled().

### exclusionPolicy : QActionGroup::ExclusionPolicy

This property holds the group exclusive checking policy

If exclusionPolicy 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 exclusionPolicy 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.

Access functions:

QActionGroup::ExclusionPolicy | exclusionPolicy() const
void | setExclusionPolicy(QActionGroup::ExclusionPolicy policy)

See also QAction::checkable.

### visible : 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.

Access functions:

bool | isVisible() const
void | setVisible(bool)

See also QAction::setEnabled().

## Member Function Documentation

### `[explicit]` QActionGroup::QActionGroup(QObject *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 instead setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional)

### `[virtual]` QActionGroup::~QActionGroup()

Destroys the action group.

### QList<QAction *> QActionGroup::actions() const

Returns the list of this groups's actions. This may be empty.

### QAction *QActionGroup::addAction(QAction *action)

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 QAction::setActionGroup().

### QAction *QActionGroup::addAction(const QString &text)

Creates and returns an action with text. 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 parent, so this function is not usually used.

See also QAction::setActionGroup().

### QAction *QActionGroup::addAction(const QIcon &icon, const QString &text)

Creates and returns an action with text and an icon. 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 QAction::setActionGroup().

### QAction *QActionGroup::checkedAction() const

Returns the currently checked action in the group, or `nullptr` if none are checked.

### bool QActionGroup::isExclusive() const

Returns true if the group is exclusive

The group is exclusive if the ExclusionPolicy is either Exclusive or ExclusionOptional.

### void QActionGroup::removeAction(QAction *action)

Removes the action from this group. The action will have no parent as a result.

See also QAction::setActionGroup().

### `[slot]` void QActionGroup::setDisabled(bool b)

This is a convenience function for the enabled property, that is useful for signals–slots connections. If b is true the action group is disabled; otherwise it is enabled.

### `[slot]` void QActionGroup::setExclusive(bool b)

Enable or disable the group exclusion checking

This is a convenience method that calls setExclusionPolicy(ExclusionPolicy::Exclusive) when b is true, else setExclusionPolicy(QActionGroup::ExclusionPolicy::None).

See also isExclusive() and QActionGroup::exclusionPolicy.