QActionGroup 类

QActionGroup 类把动作分组在一起。 更多...

头: #include <QActionGroup>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
Since: Qt 6.0
继承: QObject

公共类型

enum class ExclusionPolicy { None, Exclusive, ExclusiveOptional }

特性

公共函数

QActionGroup (QObject * parent )
virtual ~QActionGroup ()
QList<QAction *> actions () const
QAction * addAction (QAction * action )
QAction * addAction (const QString & text )
QAction * addAction (const QIcon & icon , const QString & text )
QAction * checkedAction () const
QActionGroup::ExclusionPolicy exclusionPolicy () const
bool isEnabled () const
bool isExclusive () const
bool isVisible () const
void removeAction (QAction * action )

公共槽

void setDisabled (bool b )
void setEnabled (bool)
void setExclusionPolicy (QActionGroup::ExclusionPolicy policy )
void setExclusive (bool b )
void setVisible (bool)

详细描述

QActionGroup 是基类用于类分组继承 QAction 对象在一起。

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.

另请参阅 QAction .

成员类型文档编制

enum class QActionGroup:: ExclusionPolicy

This enum specifies the different policies that can be used to control how the group performs exclusive checking on checkable actions.

常量 描述
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.

另请参阅 exclusionPolicy .

特性文档编制

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.

访问函数:

bool isEnabled () const
void setEnabled (bool)

另请参阅 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.

访问函数:

QActionGroup::ExclusionPolicy exclusionPolicy () const
void setExclusionPolicy (QActionGroup::ExclusionPolicy policy )

另请参阅 QAction::checkable .

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.

访问函数:

bool isVisible () const
void setVisible (bool)

另请参阅 QAction::setEnabled ().

成员函数文档编制

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

Constructs an action group for the parent 对象。

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 noexcept] 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 )

添加 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.

另请参阅 QAction::setActionGroup ().

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.

另请参阅 QAction::setActionGroup ().

QAction *QActionGroup:: addAction (const QIcon & icon , const QString & text )

Creates and returns an action with text 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.

另请参阅 QAction::setActionGroup ().

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 )

移除 action from this group. The action will have no parent as a result.

另请参阅 QAction::setActionGroup ().

[slot] void QActionGroup:: setDisabled ( bool b )

这是方便函数对于 enabled property, that is useful for signals–slots connections. If b is true the action group is disabled; otherwise it is enabled.

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

另请参阅 isExclusive () 和 QActionGroup::exclusionPolicy .