|  | Home · Overviews · Examples

# QActionGroup Class Reference
[com.trolltech.qt.gui module]

The `QActionGroup` class groups actions together. More...

Inherits `QObject`.

## Detailed Description

The `QActionGroup` class groups actions together.

In some situations it is useful to group actions 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 = new QActionGroup(this);
            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 an `triggered` signal when one of its actions is chosen. Each action in an action group emits its `triggered` signal as usual.

As stated above, an action group is exclusive by default; it ensures that only one checkable action is active at any one time. If you want to group checkable actions without making them exclusive, you can turn of exclusiveness by calling `setExclusive`(false).

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 use `QAction`'s setSeparator() function to make it considered a separator. Action groups are added to widgets with the QWidget::addActions() function.

See also `QAction`.