Inherits QAction.
In some situations it is useful to group actions together. For example, if you have a left justify action, a right justify action and a center action, only one of these actions should be active at any one time, and one simple way of achieving this is to group the actions together in an action group.
An action group can also be added to a menu or a toolbar as a single unit, with all the actions within the action group appearing as separate menu options and toolbar buttons.
Here's an example from examples/textedit:
QActionGroup *grp = new QActionGroup( this );
connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) );
Here we create a new action group. Since the action group is exclusive by default, only one of the actions in the group is ever active at any one time. We then connect the group's selected() signal to our textAlign() slot.
actionAlignLeft = new QAction( QPixmap::fromMimeSource( "textleft.xpm" ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" );
actionAlignLeft->setToggleAction( TRUE );
We create a left align action, add it to the toolbar and the menu and make it a toggle action. We create center and right align actions in exactly the same way.
The actions in an action group emit their activated() (and for toggle actions, toggled()) signals as usual.
The setExclusive() function is used to ensure that only one action is active at any one time: it should be used with actions which have their toggleAction set to TRUE.
Action group actions appear as individual menu options and toolbar buttons. For exclusive action groups use setUsesDropDown() to display the actions in a subwidget of any widget the action group is added to. For example, the actions would appear in a combobox in a toolbar or as a submenu in a menu.
Actions can be added to an action group using add(), but normally they are added by creating the action with the action group as parent. Actions can have separators dividing them using addSeparator(). Action groups are added to widgets with addTo().
See also Main Window and Related Classes and Basic Widgets.
The action group is exclusive by default. Call setExclusive(FALSE) to make the action group non-exclusive.
If exclusive is TRUE only one toggle action in the group will ever be active.
Normally an action is added to a group by creating it with the group as parent, so this function is not usually used.
If isExclusive() is FALSE or usesDropDown() is FALSE, the actions within the group are added to the widget individually. For example, if the widget is a menu, the actions will appear as individual menu options, and if the widget is a toolbar, the actions will appear as toolbar buttons.
If both isExclusive() and usesDropDown() are TRUE, the actions are presented either in a combobox (if w is a toolbar) or in a submenu (if w is a menu).
All actions should be added to the action group before the action group is added to the widget. If actions are added to the action group after the action group has been added to the widget these later actions will not appear.
See also exclusive, usesDropDown, and removeFrom().
Example: themes/themes.cpp.
Use add() instead, or better still create the action with the action group as its parent.
The argument is the action whose state changed to "on".
See also exclusive, on, and QAction::toggled().
If exclusive is TRUE only one toggle action in the action group can ever be active at any one time. If the user chooses another toggle action in the group the one they chose becomes active and the one that was active becomes inactive.
See also QAction::toggleAction.
Set this property's value with setExclusive() and get this property's value with isExclusive().
Exclusive action groups added to a toolbar display their actions in a combobox with the action's QAction::text and QAction::iconSet properties shown. Non-exclusive groups are represented by a tool button showing their QAction::iconSet and -- depending on QMainWindow::usesTextLabel() -- text() property.
In a popup menu the member actions are displayed in a submenu.
Changing usesDropDown only affects subsequent calls to addTo().
Note that setting this property for actions in a combobox causes calls to their QAction::setVisible(), QAction::setEnabled(), and QAction::setDisabled() functions to have no effect.
This property's default is FALSE.
Set this property's value with setUsesDropDown() and get this property's value with usesDropDown().