IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QActionGroup Class

The QActionGroup class groups actions together.

This class was introduced in Qt 6.0.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QActionGroup Class

  • Header: QActionGroup

  • Since: Qt 6.0

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Gui)

    target_link_libraries(mytarget PRIVATE Qt6::Gui)

  • qmake: QT += gui

  • Inherits: QObject

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

See also QAction

Member Type Documentation

 

enum 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

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

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:

  • exclusionPolicy() const

  • void setExclusionPolicy( policy)

See Also

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

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 *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 *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 *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

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.

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

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+