Problem with the QCheckBox



  • So, when the user ticks the checkbox, I check whether the condition is met or not.
    In case the condition is not met, then I reset the checkbox to unticked.
    When the user ticks the checkbox again, it really gets ticked, but the signal isn't fired.
    Only when the user unticks the ckeckbox again, it will work again.

    Here are some things that I have tried:

    void SLOT_CB_MyCheckbox_STATECHANGED(int state) {
        if (state && !condition)
            ui.CB_MyCheckbox->setChecked(false);
    }
    

    and

    void SLOT_CB_MyCheckbox_STATECHANGED(int state) {
        if (state && !condition)
            bool oldState = ui.CB_MyCheckbox->blockSignals(true);
            ui.CB_MyCheckbox->setChecked(true);
            ui.CB_MyCheckbox->setChecked(false);
            ui.CB_MyCheckbox->blockSignals(oldState);
            ui.CB_MyCheckbox->setChecked(false);
    }
    

    The second code snipped actually worked for some other examples where I needed to set it to some default value in the last line, instead of just false.

    Thanks for the help!


  • Lifetime Qt Champion

    Hi,

    From a user point of view: why is that check box enabled if the conditions are not met ?

    If a checkbox I click on auto-unchecks then it looks like a bug.



  • I totally agree! The user shouldn't be able to check it, if the conditions aren't fulfilled.
    I will do it this way. Thanks a lot! :)

    Could you please explain me, why the signal isn't emitted in the situation I described above?
    I couldn't figure it out...


  • Lifetime Qt Champion

    What does condition contain ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.