且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在上下文菜单中添加选中/取消选中QAction?

更新时间:2023-12-06 08:17:16

以下是手册中的相关部分.

Here is the relevant section from the manual.

可检查:bool

此属性保存该操作是否为可检查的操作.

This property holds whether the action is a checkable action.

可检查动作是具有打开/关闭状态的动作.例如,在文字处理器中,粗体工具栏按钮可以打开或关闭.不是切换动作的动作是命令动作.简单地执行命令动作,例如文件保存.默认情况下,此属性为false.

A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is false.

在某些情况下,一个切换动作的状态应取决于其他动作的状态.例如,左对齐",居中"和右对齐"切换动作是互斥的.要实现独占切换,请将相关的切换动作添加到QActionGroup :: exclusive属性设置为true的QActionGroup中.

In some situations, the state of one toggle action should depend on the state of others. For example, "Left Align", "Center" and "Right Align" toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a QActionGroup with the QActionGroup::exclusive property set to true.

访问功能:

bool isCheckable() const

void setCheckable(bool)

通知者信号:

void changed()