如何使QCheckBox只读,但不灰显 [英] How to make QCheckBox readonly, but not grayed-out

查看:290
本文介绍了如何使QCheckBox只读,但不灰显的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何用于只读选项的好方法,但也可以不灰显(几乎不可见)。

Any good way to make a checkbox readonly, but also not grayed-out (hardly visible).


  1. 我使用 setEnabled(bool)可以工作,但是复选框是灰色的,难以读取

  2. 对切​​换信号和复位状态。但是,我需要一个标志来确定该框是否是只读的,然后重置检查状态,意味着我需要创建自己的 CheckBox 类。

  3. setCheckable 也不工作,它不允许我设置一个选中的状态:

  1. I have used setEnabled(bool) which works, but the checkbox then is grayed-out and hardly readable
  2. I can react on a toggle signal and reset the state. But I would need a kind of flag to determine if the box is read-only and then reset the check state, means I need to create my own CheckBox class.
  3. setCheckable does not work either, it does not allow me to set a checked state at all:

    cb = this->ui->cb_RealWorld->isCheckable();
    this->ui->cb_RealWorld->setCheckable(true);
    this->ui->cb_RealWorld->setChecked(someValue);
    this->ui->cb_RealWorld->setCheckable(cb);


启用/停用并接受灰色样式。

So the best thing I have is to use enable/disable and accept the grayed out style.

-------编辑-------

------- Edit -------

样式表示例之后,我是希望我可以设置一个禁用复选框的样式,如启用。到目前为止失败了。更具体:如示例中所示更改图标不适用于我,也许是因为我使用的是Windows,并且图标不在示例中的路径下。

Following the stylesheet examples I was hoping I could set the style of a disabled checkbox like the one of an enabled. Failed so far to do so. More specific: Changing the icon like in the examples does not work for me, maybe because I am using Windows and the icons are not available under the path as in the examples.

PS:相关,但此处没有答案

PS: Related, but no answer here

在棘手的情况下禁用QCheckbox方式

Qt - 如何在保留选中状态的同时禁用QCheckBox?

推荐答案

按照以下我的代码:

this->ui->cb_RealWorld->setAttribute(Qt::WA_TransparentForMouseEvents);
this->ui->cb_RealWorld->setFocusPolicy(Qt::NoFocus);

这篇关于如何使QCheckBox只读,但不灰显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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