QActionGroup 类把动作分组在一起。 更多...
头: | #include <QActionGroup> |
qmake: | QT += widgets |
继承: | 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 ) |
void | hovered (QAction * action ) |
void | triggered (QAction * action ) |
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.
Here's a example (from the 菜单 范例):
alignmentGroup = new QActionGroup(this); alignmentGroup->addAction(leftAlignAct); alignmentGroup->addAction(rightAlignAct); alignmentGroup->addAction(justifyAct); alignmentGroup->addAction(centerAct); leftAlignAct->setChecked(true);
Here we create a new action group. Since the action group is exclusive by default, only one of the actions in the group is checked at any one time.
A QActionGroup emits an triggered () signal when one of its actions is chosen. Each action in an action group emits its triggered () signal as usual.
As stated above, an action group is exclusive by default; it ensures that at most only one checkable action is active at any one time. If you want to group checkable actions without making them exclusive, you can turn off exclusiveness by calling setExclusive (false).
By default the active action of an exclusive group cannot be unchecked. In some cases it may be useful to allow unchecking all the actions, you can allow this by calling setExclusionPolicy (QActionGroup::ExclusionPolicy::ExclusiveOptional).
Actions can be added to an action group using addAction (), but it is usually more convenient to specify a group when creating actions; this ensures that actions are automatically created with a parent. Actions can be visually separated from each other by adding a separator action to the group; create an action and use QAction 's setSeparator() function to make it considered a separator. Action groups are added to widgets with the QWidget::addActions () 函数。
另请参阅 QAction .
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. |
该枚举在 Qt 5.14 引入或被修改。
另请参阅 exclusionPolicy .
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 ().
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.
该特性在 Qt 5.14 引入。
访问函数:
QActionGroup::ExclusionPolicy | exclusionPolicy () const |
void | setExclusionPolicy (QActionGroup::ExclusionPolicy policy ) |
另请参阅 QAction::checkable .
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 ().
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)
[signal]
void
QActionGroup::
hovered
(
QAction
*
action
)
此信号发射当给定 action in the action group is highlighted by the user; for example, when the user pauses with the cursor over a menu option, toolbar button, or presses an action's shortcut key combination.
另请参阅 QAction::activate ().
[slot]
void
QActionGroup::
setDisabled
(
bool
b
)
这是方便函数对于 enabled 特性,这很有用对于信号/槽连接。若 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 .
[signal]
void
QActionGroup::
triggered
(
QAction
*
action
)
此信号发射当给定 action in the action group is activated by the user; for example, when the user clicks a menu option, toolbar button, or presses an action's shortcut key combination.
Connect to this signal for command actions.
另请参阅 QAction::activate ().
[虚拟]
QActionGroup::
~QActionGroup
()
Destroys the action group.
Returns the list of this groups's actions. This may be empty.
添加 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 ().
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 ().
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 ().
Returns the currently checked action in the group, or
nullptr
if none are checked.
Returns true if the group is exclusive
The group is exclusive if the ExclusionPolicy is either Exclusive or ExclusionOptional.
移除 action from this group. The action will have no parent as a result.
另请参阅 QAction::setActionGroup ().