QPushButton default windows style sheet
-
Hello,
All I want to do is to change the default windows QPushButton color from blue to green, saving all other style parameters intact. I looked everywhere for the default parameters with no success. Calling styleSheet() returns empty string.Thanks,
Ronen -
Hi and welcome
Sadly Its not possible to get a default style sheet from a Widget.
Its using a QStyle which is not a style sheet. So it will return empty string as you seenWhen using a Style Sheets, its all or nothing. So Often one has to specify extra settings to get
the exact look wanted. -
@mrjj tnx for the warm welcome.
The default is QWindowsStyle but there isn't an access to the button's color.
QWindowsStylePrivate is not guarantied so I can't count on using it with QWindowsStyle protected constructor.
I thought maybe I could use the palette but it doesn't work.
It's so frustrating that I can't change only part of the parameters and even if I want to create a new style sheet I can't find what are the default parameters to hard code them. -
Colors of a button are style dependent as already stated. And when I say style I don't mean QStyle (although that's how it is exposed in Qt), I mean OS style eg. Luna on XP, Aero on Vista/7 or some other styles of window managers elsewhere. Some styles on some platforms use fancy visual effects, gradients, glows, animations etc. You can't get a default color because there simply might not be any single color to give to you.
Stylesheets are a totally different beasts. The default native drawing doesn't use stylesheets. They are a way to override native style dependent painting with HTML-like drawing. Usually if you change one of the basic style elements like border or background Qt disables native painting entirely and falls back to a simple HTML box model. So in short you can't change just one property of a stylesheet and keep original native style painting. There are exceptions to that (e.g. changing text color), but that's what they are - exceptions. In general it's either stylesheets or native painting. Mixing is generally not possible and even if it has the desired result with one theme it might not with another.
Palette is yet another thing. Most platforms define some sort of palette that a user can adjust and that transfers to Qt's QPalette. But nowadays most platforms divert from the idea of letting you control every single aspect of ui look and instead offer you simple things like "theme color". For Qt this means that changing a palette is usually a bad idea and the results will vary from user to user. Some styles ignore palette colors and apply their fancy themed drawing like gradients and such. Some styles will ignore one subset of a palette, some will ignore another. It's generally a minefield to try and control colors with palettes consistently. I advise against that.
-
Is there a reference which holds the attributes of the different default styles (Windows, Mac etc.) ?
Attributes of what? If you mean stylesheet values then it's mostly not possible to mimic native look with it.
Widgets in native styles are not drawn with stylesheets. They use native methods wrapped in QStyle::drawControl and friends, which delegate the drawing to the OS via platform plugin. -
I'm trying to figure if QProxyStyle can be of any use. Is it a good option for changing single style values?
-
It depends on which elements you want to change. The point is that there is no good way to change single elements (by element I mean parts of a single control).
The only thing I found you can change pretty reliable is text color. Most other stuff is highly platform/style dependent. For example platform plugin usually gets a button from OS as a bitmap of some sort. There's usually no OS provided API, let alone exposed by Qt, to get access to sub-elements like bevels, gradient components etc.
I might be exaggerating a little, but It's mostly all or nothing deal.
-
@Chris-Kawa that's what I eventually figured :(
Thanks a lot for your help and great explanations! -
@Chris-Kawa Sorry for bringing up the really old thread, but a quick question I have is simple, after using a stylesheet is there not a way to get the control to revert to os-dependant rendering?
-
@KY4CT
My understanding (stand to be corrected) is that if you supply stylesheet rules for a widget type (might depend on widget or what you set in the sheet, not sure) that replaces the OS/theme and you no longer get that. Don't supply such a rule if you want the original appearance. -
To remove stylesheet style simply set an empty string i.e.
someWidget->setStyleSheet("border: 1px solid red; background-color: blue;"); // sets a stylesheet someWidget->setStyleSheet({}); // removes a stylesheet