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 aQCheckBox
usingQWidget::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?Thanks.
-
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.
-
Hi
What platform is that ?
On windows (10) it seems to use black anyway
-
@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.
-
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.