6.0.0-rc4Source

QActionGroup Class

The QActionGroup class groups actions together. More…

Header#include <QActionGroup>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes
InheritsQObject

List of all members, including inherited members

Public Types

Public Functions

QActionGroup(QObject *parent = nullptr)
~QActionGroup()
QAction *addAction(QAction *action)
QAction *addAction(const QString &text)
voidremoveAction(QAction *action)
QList<QAction *>actions() const
QAction *checkedAction() const
boolisExclusive() const
boolisEnabled() const
boolisVisible() const
ExclusionPolicyexclusionPolicy() const

Public Slots

voidsetEnabled(bool enabled)
voidsetDisabled(bool disabled)
voidsetVisible(bool visible)
voidsetExclusive(bool exclusive)
voidsetExclusionPolicy(ExclusionPolicy policy)

Signals

voidtriggered(QAction *action)
voidhovered(QAction *action)

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.

ConstantDescription
QActionGroup::NoneAny number of them.
QActionGroup::ExclusiveExactly one, once one is checked: triggering the checked one does not uncheck it.
QActionGroup::ExclusiveOptionalAt most one: triggering the checked one unchecks it.

Member Function Documentation

[explicit] QActionGroup::QActionGroup(QObject *parent = nullptr)

Constructs an empty, exclusive action group with the given parent.

[override] 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().

[signal] 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().

[slot] 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().

[slot] void QActionGroup::setEnabled(bool enabled)

Enables or disables all the actions of the group, as enabled says.

See also isEnabled().

[slot] void QActionGroup::setExclusionPolicy(ExclusionPolicy policy)

Sets how many checkable actions of the group can be checked to policy.

See also exclusionPolicy().

[slot] void QActionGroup::setExclusive(bool exclusive)

Sets whether the group is exclusive to exclusive.

See also isExclusive().

[slot] void QActionGroup::setVisible(bool visible)

Shows or hides all the actions of the group, as visible says.

See also isVisible().

[signal] void QActionGroup::triggered(QAction *action)

This signal is emitted when the user triggers an action of the group, with that action.