QActionGroup Class
The QActionGroup class groups actions together. More…
| Header | #include <QActionGroup> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Gui) |
| Module | Nt GUI C++ Classes |
| Inherits | QObject |
List of all members, including inherited members
Public Types
| enum | ExclusionPolicy |
Public Functions
| QActionGroup(QObject *parent = nullptr) | |
| ~QActionGroup() | |
| QAction * | addAction(QAction *action) |
| QAction * | addAction(const QString &text) |
| void | removeAction(QAction *action) |
| QList<QAction *> | actions() const |
| QAction * | checkedAction() const |
| bool | isExclusive() const |
| bool | isEnabled() const |
| bool | isVisible() const |
| ExclusionPolicy | exclusionPolicy() const |
Public Slots
| void | setEnabled(bool enabled) |
| void | setDisabled(bool disabled) |
| void | setVisible(bool visible) |
| void | setExclusive(bool exclusive) |
| void | setExclusionPolicy(ExclusionPolicy policy) |
Signals
Detailed Description
Checkable actions in an exclusive group are like radio buttons: checking one unchecks the one that was checked. The group also enables, disables, shows and hides all its actions at once, and reports the triggered and hovered action with one signal:
QActionGroup *align = new QActionGroup(this);
QAction *left = align->addAction("Left");
QAction *right = align->addAction("Right");
left->setCheckable(true);
right->setCheckable(true);
left->setChecked(true);
connect(align, &QActionGroup::triggered, this, &Editor::setAlignment);
See also QAction.
Differences from Qt
The actions are not owned by the group unless the group made them with addAction(const QString &).
Member Type Documentation
enum QActionGroup::ExclusionPolicy
This enum says how many of the checkable actions of a group can be checked.
| Constant | Description |
|---|---|
QActionGroup::None | Any number of them. |
QActionGroup::Exclusive | Exactly one, once one is checked: triggering the checked one does not uncheck it. |
QActionGroup::ExclusiveOptional | At most one: triggering the checked one unchecks it. |
Member Function Documentation
QActionGroup::QActionGroup(QObject *parent = nullptr)
Constructs an empty, exclusive action group with the given parent.
QActionGroup::~QActionGroup()
Destroys the group. Its actions stay, outside of any group.
QList<QAction *> QActionGroup::actions() const
Returns the actions of the group, in the order in which they were added.
QAction * QActionGroup::addAction(QAction *action)
Adds action to the group, and returns it. An action is in one group at a time. The action takes the enabled and visible state of the group, and if the group is exclusive and the action is checked, it is the one that stays checked.
See also removeAction().
QAction * QActionGroup::addAction(const QString &text)
Creates an action with the given text, adds it to the group, and returns it. The group owns the action.
See also addAction().
QAction * QActionGroup::checkedAction() const
Returns the action that is checked; nullptr if none is.
ExclusionPolicy QActionGroup::exclusionPolicy() const
Returns how many checkable actions of the group can be checked, Exclusive by default.
See also setExclusionPolicy().
void QActionGroup::hovered(QAction *action)
This signal is emitted when the user hovers over an action of the group in a menu, with that action.
bool QActionGroup::isEnabled() const
Returns false if the group has been disabled; otherwise returns true.
See also setEnabled().
bool QActionGroup::isExclusive() const
Returns true if the group allows one checked action at most; otherwise returns false.
See also setExclusive() and exclusionPolicy().
bool QActionGroup::isVisible() const
Returns false if the group has been hidden; otherwise returns true.
See also setVisible().
void QActionGroup::removeAction(QAction *action)
Takes action out of the group.
See also addAction().
void QActionGroup::setDisabled(bool disabled)
Disables all the actions of the group if disabled is true, and enables them if it is false.
See also setEnabled().
void QActionGroup::setEnabled(bool enabled)
Enables or disables all the actions of the group, as enabled says.
See also isEnabled().
void QActionGroup::setExclusionPolicy(ExclusionPolicy policy)
Sets how many checkable actions of the group can be checked to policy.
See also exclusionPolicy().
void QActionGroup::setExclusive(bool exclusive)
Sets whether the group is exclusive to exclusive.
See also isExclusive().
void QActionGroup::setVisible(bool visible)
Shows or hides all the actions of the group, as visible says.
See also isVisible().
void QActionGroup::triggered(QAction *action)
This signal is emitted when the user triggers an action of the group, with that action.