[Solved] CSS on custom widget
I have a class that inherits from QPushButton. I want to customize it's look and feel with CSS, but I don't know how to access it from CSS.
The widget is promoted on Qt Designer from QPushButton to the custom class.
But it's not working.
returns QPushButton, not MyClassName.
Is there a simple way to access all instances of that class?
Using QPushButton[objectName|="prefix"] might work for me, but my custom buttons are not named with a "prefix-", they are named with a suffix (and withouht hyphens). Is there an equivalent selector for suffixes or is it possible to use wildcards? I would like to avoid changing the names to keep consistent with the naming style I've been using until now.
I just found that [attribute$=value] is just what I need, but QtDesigner complains about it being invalid CSS... I guess Qt does not support CSS3, does it?
your class needs to have the Q_OBJECT macro in order to get the correct class name with the meta object system.
For the supported selector types see "this":http://qt-project.org/doc/qt-4.8/stylesheet-syntax.html#selector-types.
Have You looked on it..
Thanks for your quick replies.
bq. Have You looked on it..
yes, that's the first place I looked. But I didn't find a similar example.
bq. your class needs to have the Q_OBJECT macro in order to get the correct class name with the meta object system.
You were right, I was missing the Q_OBJECT macro. Thank you very much!
For future reference, I needed to run qmake (Menu>Build>Run qmake) after adding the macro and prior to compiling. Otherwise I got an
@undefined reference to `vtable@
Needs compiling to see the changes in the CSS (no update on QDesigner)