Solved Simple background-color stylesheet disturbs appearance on macOS
-
Hi and thanks for reading,
when I try to set a simple stylesheet to change the background color of - for example - a QPushButton, the macOS look disappears and the button becomes big and ugly (cf. the two screenshots).
This is the case when I set it in Creator, and when I apply it programmatically via a simple
button->setStyleSheet("QPushButton {background-color: red}");
Polishing the style does not do anything.
It happens for me on macOS High Sierra with Qt 5.13.2 / Clang 10.0. Of course, all is well on Linux and Windows.
I could not find a known issue; is there anything I could be doing wrong, or that I could try?
Regards
-
@gefal said in Simple background-color stylesheet disturbs appearance on macOS:
when I try to set a simple stylesheet to change the background color of - for example - a QPushButton, the macOS look disappears and the button becomes big and ugly
Hi and welcome to the forums
That is expected as when you apply a stylesheet you disable the normal
drawing so using stylesheets is an all or nothing approach.You can try changing the background using the Palette but it might
not be respected/used by the QStyle for a given platform. -
Thanks for your reply, got it.
I thought stylesheets would add on to the theme that is being used on the operating system, given that all is well on Linux. I don't understand why setting a stylesheet for, say, the text color, does not alter the appearance then.
I'm also a little surprised that the size changes so drastically, even if I set fixed proportions for the buttons. I suppose this also explains why a macOS-styled button I give a fixed square size is everything but square?
A Palette is not an option for me (without a huge restructure at least), because the actual program is quite complicated and relies on styles being changed when certain properties are set.Anyway, thanks again, I'll find a workaround.
Regards -
Hi and welcome to devnet,
There's no theming in Qt per se. QStyle subclasses are used to render controls as the OS does. The stylesheets have a dedicated QStyle subclass that renders what is requested in the stylesheet and that takes precedence as explained in their documentation.
On Linux is might be less visible depending on the desktop environment you use and its theming.
-
Hi,
thanks again, it's becoming a bit more clear to me.
On the main style sheet page it says"Style sheets are applied on top of the current widget style, meaning that your applications will look as native as possible, but any style sheet constraints will be taken into consideration."
But just below it actually explains it:
"When a style sheet is active, the QStyle returned by QWidget::style() is a wrapper "style sheet" style, not the platform-specific style. The wrapper style ensures that any active style sheet is respected and otherwise forwards the drawing operations to the underlying, platform-specific style (e.g., QWindowsVistaStyle on Windows)."
For potential future readers, with your hints I did dig up this explanation that goes into a little detail (and also explains why setting a different font style does not affect the look):
If you don't mind my asking a couple of follow-up questions:
Does the sentence from https://doc.qt.io/qt-5/qstyle.html
"Warning: Qt style sheets are currently not supported for custom QStyle subclasses. We plan to address this in some future release."
refer to this or would this not help?If I understand correctly, as soon as I use any stylesheet in any way, basically to guarantee a uniform look across my application I would have to style all my widgets manually? Because I could never know what the (size) difference between the two styling methods are? I don't mind a look without rounded corners, but I'm still put off by the size difference.
I saw through QStyleFactory that "Fusion" is available on all three platforms I have. How reasonable is it to expect it to be there on a random user's system? Unless more funding comes in I'd be happy with just using that.
Thanks a bunch,
best -
AFAIR, fusion is built by default so you should have it. If you deploy your application, just ensure that the corresponding plugin is deployed as well.