Qt Stylesheet mystery
My Desktop Qt app has a large stylesheet applied. It's applied for the QApplication derived class I am using:
It works well for all QWidget objects I define and use. (using *.ui files).
My problem begins when i promote one of my QWidgets in the *.ui file I'm using to one of my own QWidget derived classes.
When my widget was QWidget, the following worked and changed the background image:
When I promoted the element to my custom QWidget derived class and changed to:
I no longer see my background image. Obviously I am missing something. What is it... I hope one of you knows.
I've seen this before with promoting widgets.
The only solution i could find is to do al stylesheet stuff in code not in Qt Designer.
It's a FAQ. Read the entry for QWidget in here: [[doc:stylesheet-reference]]
If you subclass from QWidget, you need to provide a paintEvent for your custom QWidget as below:
void CustomWidget::paintEvent(QPaintEvent *)
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
The above code is a no-operation if there is no stylesheet set.
Warning: Make sure you define the Q_OBJECT macro for your custom widget.
that did it. my bad. thanks.