Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

c++ - How to make QCheckBox readonly, but not grayed-out

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

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

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: Related, but no answer here

Disabling a QCheckbox in a tricky way
Qt - How to disable QCheckBox while retaining checked state?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Following the below my code:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...