Qt - 如何禁用QCheckBox同时保持选中状态? [英] Qt - How to disable QCheckBox while retaining checked state?

查看:2691
本文介绍了Qt - 如何禁用QCheckBox同时保持选中状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个复选框的对话框,我们称它们为A和B.当A未选中时,B应该能够根据用户需要切换。当选中A IS时,B不能切换。现在我在我的构造函数中有以下对话框:

I have a dialog with two checkboxes, let's call them A and B. When A is NOT checked, B should be able to be toggled as the user desires. When A IS checked, B should not be able to be toggled. Right now I have the following in my constructor function for the dialog:

connect(ui->A, SIGNAL(toggled(bool)),
        this, SLOT(setBCheckable(bool)));

...然后我的功能如下:

...and then I have that function as this:

void MyClass::setBCheckable(bool AChecked)
{
    if(AChecked)
    {
        ui->B->setCheckable(false);
    }
    else
    {
        ui->B->setCheckable(true);
    }
}

但是,当我这样做,当我点击A,B将APPEAR保留它的状态,但然后当我将鼠标移动(不管A是否仍然点击,只是下一次我鼠标结束后检查A),它刷新B,不是点击。我不能有它这样做,因为我需要的功能来保留B的值,即使B不能改变。有办法做到这一点吗?总而言之,我需要一个方法为QCheckBox保持它的检查状态,即使按钮不能切换。提前感谢!

However, when I do this, I've noticed that when I click A, B will APPEAR to retain it's status, but then when I move the mouse over it (whether A is still clicked or not, just the next time I mouse over after checking A), it refreshes B to NOT being clicked. I cannot have it doing this, since I need the function to retain the value for B even when B cannot be changed. Is there a way to do this? To summarize, I need a way for a QCheckBox to keep it's checked status even when the button cannot be toggled. Thanks in advance!

推荐答案

使用函数 setEnabled(false)将停用,但应保持其状态

use the function setEnabled(false) this will disable but should keep its state

这篇关于Qt - 如何禁用QCheckBox同时保持选中状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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