Qt Designer - Global Stylesheet
-
Hello, I have created an app and I read several places that Qt Designer supports global stylesheets instead of making the stylesheet on each object.
My problem is that I cannot get this to work.
For example if i call a QPushButton that is inside a QFrame, it doesn't add the styling.
QFrame{ border: 0px solid black; border-radius: 10px; background: rgb(127, 127, 127); } QPushButton{ top: 200px; background: pink; }
The biggest reason I would like this to work, is because else I am not able to create my program like I want it. I want to when I hover a button, that another button changes color.
Like this:
QPushButton#Achievement:hover + QPushButton#Achievement2{ background: rgb(232, 232, 232); color: rgb(104, 104, 104); }
But this clearly doesn't work too, as I cannot call any other objects inside the stylesheets for a specific object.
So where do I find the global stylesheet so I can make the above hover work?
-
You can set the stylesheet for the whole application like using setStyleSheet().
If you set the style sheet for one widget, it will be automatically applied to all it's children.
-
@sierdzio
As the title said, this is with QT Designer,
How do i call the setStyleSheet within QT Designer? -
@uruloke said:
How do i call the setStyleSheet within QT Designer?
You can't, as far as I am aware. But your code will later be used in an application, right? And there you can set the stylesheet using setStyleSheet().
-
@sierdzio
Well yes ofc, It will later be used with Python.
Just annoying to test my code out if I cannot do all the things in one place...But how do I use the set StyleSheet() with python? just to be sure how to use it correctly.
-
I think the API for PyQt and other ports is the same as for Qt itself. Just check out the documentation for QWidget's setStyleSheet() and QApplication's setStyleSheet()
-
@sierdzio
Thank you, that acutally works.
Now I just have to port my whole program into python instead of in Pyqt designer... -
hey there,
you can create a "dummy" widget in Designer, add stylesheet to it in designer, then use this widget stylesheet in the code like this to have a clean 1 line setStyleSheet()// App Stylesheet (hack so I can type stylesheet in designer instead of source code) Z_StyleSheet styleSheetDummy; app.setStyleSheet(styleSheetDummy.styleSheet());