0

I'm using style sheets to edit some checkboxes to my liking. I can change the color of the text with

color: rgb(255,0,0);      // Red text

and I can change the look of the checkbox itself with

QCheckBox::indicator
{
    background-color: qlineargradient(...);
    border: 2px solid rgb(170, 57, 57);
    width: 50px;
    height: 50px;
    border-radius: 10px;
};

...but I can't do both at the same time. If I place both sections of code in the style sheet together, the text color edit gets ignored, regardless of whether I put it inside or outside the indicator bracketed section. I've noticed that this also applies to background color changes.

I assume I'm missing something about how style sheets work (especially regarding QCheckBox), but none of the Qt documentation I've found so far is helpful (I'm using Qt 4.8 in Qt Creator).

Churchbus
  • 53
  • 5
  • Where are you setting `color: rgb(255,0,0); `? Are you doing this via Qt Creator with setStylesheet? – Rick Smith Jun 03 '15 at 19:47
  • Using the answer supplied in duplicate question works for me. If this does not help you, please provide some information about how what you are doing is different. Using `QCheckBox { color: red }` ***and*** `QCheckBox::indicator{...}` causes me no problems. If you don't understand why this works, update your question and I can explain. – Rick Smith Jun 03 '15 at 19:53
  • Ah, I see now. I had seen that other question before, but I missed the part where you have to include `QCheckBox { }` to specify what you're changing. In all my other style sheets, I could just throw in `color: rgb(255,0,0);` without any other identifiers, and it would work. Thanks for the help, and feel free to mark this question as duplicate or whatever else needs to be done. – Churchbus Jun 03 '15 at 20:00
  • 1
    Glad to see you got it. Also, it is not a good idea to use `color` in this way because any children will inherit the cascading style (look up how CSS cascades) and it will be a pain to track down where stray styles are coming from. I always put all of my CSS on the top-most widget and narrow their reach as best I can. – Rick Smith Jun 03 '15 at 20:04

0 Answers0