Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] Grey out/Disable the QCheckBox text in Qt

    General and Desktop
    2
    6
    7958
    Loading More Posts
    • 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.
    • S
      Stoned Jesus last edited by

      I am working on a sample app where I need to disable the text of checkbox when checkbox is not checked and enable it when checkbox is checked.

      Code:

      @if(ui->checkBox->isChecked() == true)
      {
      // Enable the text of checkbox
      }

      else
      {
      // Disable the text of checkbox
      }@

      I have looked through various articles but I haven't got the right solution. Please help :)

      --
      Thanks & Regards,
      Stoned Jesus

      1 Reply Last reply Reply Quote 0
      • Q
        qxoz last edited by

        Hi!
        You can experiment with qss. But as a fast solution you can use checkbox(without text)+label combination. That's maybe not rightest but fast :)

        1 Reply Last reply Reply Quote 0
        • S
          Stoned Jesus last edited by

          Yes i used. I tried this:

          @ui->checkBox->setStyleSheet( "QCheckBox::indicator:checked { {color: black;} } QCheckBox::indicator:unchecked {{color: grey;}}");@

          But again this doesnt seem to work. Am i making a mistake???

          [quote author="qxoz" date="1366802036"]Hi!
          You can experiment with qss. But as a fast solution you can use checkbox(without text)+label combination. That's maybe not rightest but fast :)[/quote]

          --
          Thanks & Regards,
          Stoned Jesus

          1 Reply Last reply Reply Quote 0
          • Q
            qxoz last edited by

            This works for me:
            @QCheckBox:checked{color: black;}
            QCheckBox:unchecked{color: grey;}@
            or
            @QCheckBox#checkBox:checked{color: black;}
            QCheckBox#checkBox:unchecked{color: grey;}@

            1 Reply Last reply Reply Quote 0
            • S
              Stoned Jesus last edited by

              Thanks brother :) It works
              [quote author="qxoz" date="1366802657"]This works for me:
              @QCheckBox:checked{color: black;}
              QCheckBox:unchecked{color: grey;}@
              or
              @QCheckBox#checkBox:checked{color: black;}
              QCheckBox#checkBox:unchecked{color: grey;}@
              [/quote]

              --
              Thanks & Regards,
              Stoned Jesus

              1 Reply Last reply Reply Quote 0
              • Q
                qxoz last edited by

                You're welcome :)
                I am glad to be helpful.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post