How to use QSS on an object that is not a QWidget?
-
Hi,
I'm writing an application that implements separately (in different classes):- The (graphical) data to display (for instance a 3D mesh),
- The method to display the data(for instance use OpenGL to display the mesh)
- The view that displays the data(for instance a QOpenGLWidget)
To be more precise, the "view" is configured with a set of "renderers", and a set of "objects to render". Then when the view has to perform the drawing it sends all the objects to render to all the renderers. And each renderer identifies which object it can render.
So, renderers usually do not inherit from QWidget. Lot of them, even do not inherit from QObject. But, I need to find a way to use my QSS file to inform them of the drawing properties they must use (object color, line, width, and so on).
I found a post in 2010 with the same problem (http://www.qtcentre.org/threads/35545-Hijack-QWidget-setStyleSheet-for-a-QObject-class-(non-QWidget) ). But the solutions supposes that the object is somewhere in an QObject hierarchy. That is not my case (the renderers have no parent because they can be shared by several views).
So, for the moment the concerned renderers inherits from QWidget, event if they are not widgets. And I search a way to remove this inheritance. Any idea?
Thanks.
-
@Alain38-0 said in How to use QSS on an object that is not a QWidget?:
So, for the moment the concerned renderers inherits from QWidget, event if they are not widgets. And I search a way to remove this inheritance. Any idea?
The answer is still the same and i bet it wont change the next years.
Only QWidgets get polished by the Qt stylesheet style.You can define (styleable) properties for a top-contianer QWidget which then forwards them to the non-QWidget members.
For example (where "MyProperty" is declared using
Q_PROPERTY
):MyContainerWidget { qproperty-MyProperty: "...."; }