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. Changing the color of a QCheckBox text also changes the check-sign color

Changing the color of a QCheckBox text also changes the check-sign color

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.2k Views 2 Watching
  • 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.
  • C Offline
    C Offline
    ChainReaction
    wrote on last edited by ChainReaction
    #1

    Hey.
    I am trying to create color changes in the label of a QCheckBox using QWidget::setStyleSheet:

    void Trigger::updateTrigger(bool state) { // this is a slot connected to the checkbox 'clicked' signal
        if (state) {
            _trigger->setStyleSheet("QCheckBox {color: red;}");
            _trigger->setText("Waiting for trigger...");
        } else {
            _trigger->setStyleSheet("QCheckBox {color: black;}");
            _trigger->setText("Check Trigger box to start");
        }
    }
    

    This almost works.
    0_1552065596104_5019b625-2ef5-4f77-8669-0058b66b0633-image.png
    See how the check sign is also red?
    I want the label, and only the label, to change its color.

    What am I doing wrong?
    Is it even possible?

    Thanks.

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      depends on how the QCheckBox is implemented and how it uses color roles from the palette.

      A work-around would be to create a subclass in which the main checkbox has no text, but that the subclass also contains a QLabel with whatever attributes you desire.

      If you meet the AI on the road, kill it.

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        What platform is that ?
        On windows (10) it seems to use black anyway
        alt text

        C 1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          What platform is that ?
          On windows (10) it seems to use black anyway
          alt text

          C Offline
          C Offline
          ChainReaction
          wrote on last edited by ChainReaction
          #4

          @Kent-Dorfman thanks. I will try this wa as a last resort.

          @mrjj can you remind me again how do I check what is the platform (I am running linux if that's what you meant)?

          Thanks.

          1 Reply Last reply
          0
          • Kent-DorfmanK Offline
            Kent-DorfmanK Offline
            Kent-Dorfman
            wrote on last edited by
            #5

            yes, he meant operating system...and good idea to also post Qt version number used. Good ettiquitte would be to always tell what Qt version and OS you are using but that would be like training cats to dance in a chorus line.

            If you meet the AI on the road, kill it.

            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