partially update default stylesheet
-
Hi,
Another option is to create a QProxyStyle to do the painting you want.
-
Hi,
Another option is to create a QProxyStyle to do the painting you want.
@SGaist said in partially update default stylesheet:
Another option is to create a QProxyStyle to do the painting you want.
I consider this quite complicated. And sometimes I just want the native look and just change a single thing (like the OP). I don't think it is reasonable that everybody reimplements the native look with a QProxyStyle. It would be more helpful if it was provided by Qt directly. At least with QtWidget I would rather be able to just set the palette to switch between light mode and dark mode and not write stylesheets for that.
-
There's no need to reimplement the whole style in the QProxyStyle. Just the things that you actually want to be modified.
See this nice article from KDAB on the matter. -
@SGaist said in partially update default stylesheet:
Another option is to create a QProxyStyle to do the painting you want.
I consider this quite complicated. And sometimes I just want the native look and just change a single thing (like the OP). I don't think it is reasonable that everybody reimplements the native look with a QProxyStyle. It would be more helpful if it was provided by Qt directly. At least with QtWidget I would rather be able to just set the palette to switch between light mode and dark mode and not write stylesheets for that.
@SimonSchroeder The problem is that "native style" means it uses native OS facilities to paint the control. Sometimes there's some level of customization provided by those, but more often than not there's none.
Take a widget background as an example - a Windows native style uses a call to DrawThemeBackgroundEx (among others). It just gives the OS a region and gets a painted image back. There's some degree of customization, e.g. you can pass a flag to omit a frame, but Qt code doesn't know what is drawn - a gradient, rounded corners, how thick the frame is etc.
The same executable with the same native style plugin will get something different on Windows Vista, 8, 10 or 11. That being said Qt can't "just let you change one thing". It gets all the things as a single bitmap, so you either take it or recreate the whole thing as a custom style (qss). Qt can't do it for you because it's dynamic and depends on the OS. If you decide to do it you take responsibility for it not looking native anymore. Trying to recreate native look with qss is futile, because native look can change at any given OS update. -
There's no need to reimplement the whole style in the QProxyStyle. Just the things that you actually want to be modified.
See this nice article from KDAB on the matter.@SGaist said in partially update default stylesheet:
There's no need to reimplement the whole style in the QProxyStyle. Just the things that you actually want to be modified.
See this nice article from KDAB on the matter.I didn't know about the article. However, I'm not entirely sure if the statement "Just the things that you actually want to be modified" is correct. It seems as if the article assumes that you don't want to use a native style anyway because the style should look the same on all platforms. Correct me if I'm wrong, but if I am using the Windows native style and I just want to change the border color of a
QPushButtonin my ownQStyle-derived class, I only can try to change a single thing if I'm calling theQPushButtonpaint method of the underlying style. This actually does not change anything. Instead, I need to draw my own button entirely to apply the changes because the native Windows style does not respect my wishes.Or I am wrong about this and there is actually some code that copies the native style (contrary to what @Chris-Kawa said). Then the big question is why I can't just change this by setting the QPalette instead...
-
@SGaist said in partially update default stylesheet:
There's no need to reimplement the whole style in the QProxyStyle. Just the things that you actually want to be modified.
See this nice article from KDAB on the matter.I didn't know about the article. However, I'm not entirely sure if the statement "Just the things that you actually want to be modified" is correct. It seems as if the article assumes that you don't want to use a native style anyway because the style should look the same on all platforms. Correct me if I'm wrong, but if I am using the Windows native style and I just want to change the border color of a
QPushButtonin my ownQStyle-derived class, I only can try to change a single thing if I'm calling theQPushButtonpaint method of the underlying style. This actually does not change anything. Instead, I need to draw my own button entirely to apply the changes because the native Windows style does not respect my wishes.Or I am wrong about this and there is actually some code that copies the native style (contrary to what @Chris-Kawa said). Then the big question is why I can't just change this by setting the QPalette instead...
@SimonSchroeder Native styles are implemented such that they follow the original platform style and are thus free to ignore modified palette values to stay coherent.
Thus, depending on what you want to change, you will need to check what the original style does underneath. I am not claiming that it's simple for everything, far from it.
Many times, it's a question of re-implementing drawPrimitive to either call the base class implementation with modified values or having your own implementation based out of the original class.