Important: Please read the Qt Code of Conduct -

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

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


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

  • Lifetime Qt Champion

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

  • @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)?


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

Log in to reply