Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with the QCheckBox
QtWS25 Last Chance

Problem with the QCheckBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcheckboxstate
4 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    letinas
    wrote on last edited by letinas
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • L Offline
        L Offline
        letinas
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What does condition contain ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved