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



  • Good to know, and well done for sharing the solution :) If this is not noted in the documentation you might want to file a bug report perhaps? It sure looks like one...



  • Not sure if I'd consider it a bug of major importance; but I do agree with you that it should pointed out in the documentation which comment styles are allowed and not allowed



  • I made a Doc Note on the relevant page in the documentation: [[doc:stylesheet-syntax]]



  • Good work Andre!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.