如何在上下文菜单中添加选中/取消选中QAction? [英] How to add check/Uncheck QAction in the context menu?

查看:961
本文介绍了如何在上下文菜单中添加选中/取消选中QAction?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Qt中创建了一个上下文菜单,我需要菜单中的项目以选中/未选中的方式工作,以便每次单击相应项目时都可以切换.如下所示,如何将此功能添加到QAction?

I have created a context menu in Qt and I need the items in the menu works in a checked/Unchecked manner so that it toggles for every click on the respective item. How to add this feature to the QAction just like shown below?

推荐答案

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

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()

这篇关于如何在上下文菜单中添加选中/取消选中QAction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆