[Interest] Changing QSpinEdit color

Till Oliver Knoll till.oliver.knoll at gmail.com
Thu Jun 7 08:45:07 CEST 2012


Am 06.06.2012 um 13:20 schrieb André Somers <andre at familiesomers.nl>:

> ... setPalette cannot be relied on, and is thus effectively useless. Pitty is: style sheet support is incomplete (no API for custom widgets), so in some cases (mainly if you use your own widgets), you're basically screwed. You cannot rely on the palette to work properly, but you cannot use style sheets either.

What exactly do you mean by "own widgets"? "Custom widgets" as in "You are responsible for painting everything yourself"? So why would one ignore the palette colours - in her own drawing code, that is - when there was a need for that in the first place? Or did you mean "3rd party custom widgets"?

Anyway, I agree that it is a mess having to deal with two different APIs to reliably set the background colour of some line edit widget (style sheet), which at the same time should have the same background colour as some other custom widget (setPalette()), for instance.

I wasn't aware that the "style sheet API" wasn't available to custom painting code. I guess one could always provide a custom setStyleSheet method, try to parse (a subset of) the CSS yourself and then merge the result with the (subset) CSS result from the parent widget.

However IIRC widgets "where it is reasonable to set the background colour" - QLineEdit where you want to indicate that some input is missing or wrong, for instance - work cross-platform with setPalette.

But more often than never people want to also set the colour of some push button or tab switching "button". At least on a Mac that is absolutely wacko to do so: people go absolutely banana if they don't see their blue bubbly buttons or most recently their "dull gray with decent lighter gray tab highlighting" tab buttons! Didn't you know? Colours have basically become outlawed (icons in Finder, anyone?) in the "greatest OS X we've ever had" - yikes! ;)

Bottom line: if the native painting code doesn't respect your setPalette calls, then there might be a good reason ;)

Cheers,
  Oliver


More information about the Interest mailing list