Stylesheet not being applied to children of custom widget which subclasses QWidget
-
HI guys,
I've been working on this problem for a while and I'm hoping you might be able to help me with it.
My project has a qss stylesheet which is used to hold all styling for the all widgets in the project. I'm currently trying to style some QPushButton widgets. One class whose QPushButtons I've been styling is a subclass of QFrame and those buttons get styled fine from the stylesheet using syntax like:
@MyCustomQFrameSubClass > QPushButton#objectName {
order-image: url(:/imager.png) 0 0 0 0;
}@However when I try to apply similar styling to the QPushButtons which subclasses QWidget I don't get any styling. Here's an example of the styling I'm using:
@MyCustomQWidgetSubClass > QPushButton#objectName {
order-image: url(:/imager.png) 0 0 0 0;
}@I have re-implemented the paintEvent for the widget which subclasses QWidget as follows:
@void MyCustomQWidgetSubClass::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
} @If anyone has any suggestions for solutions I'd greatly appreciate it.
Brendan
-
Turns out that it was a simple solution, but it might help someone else.
I had a comment in the stylesheet which was in the wrong format, example below, so anything below it wasn't getting parsed:
@/This kind of comment is ok/
//This kind of comment will cause an error@
It took me ages to figure this out so hopefully it'll help save someone time at some stage.
Brendan