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. [SOLVED] Grey out/Disable the QCheckBox text in Qt

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

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 8.9k 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.
  • S Offline
    S Offline
    Stoned Jesus
    wrote on last edited by
    #1

    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
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        Stoned Jesus
        wrote on last edited by
        #3

        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
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          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
          0
          • S Offline
            S Offline
            Stoned Jesus
            wrote on last edited by
            #5

            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
            0
            • Q Offline
              Q Offline
              qxoz
              wrote on last edited by
              #6

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

              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