Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Stylesheet not being applied to children of custom widget which subclasses QWidget

    General and Desktop
    2
    6
    4825
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bren85 last edited by

      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

      1 Reply Last reply Reply Quote 0
      • B
        bren85 last edited by

        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

        1 Reply Last reply Reply Quote 0
        • ?
          Guest last edited by

          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...

          1 Reply Last reply Reply Quote 0
          • B
            bren85 last edited by

            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

            1 Reply Last reply Reply Quote 0
            • A
              andre last edited by

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

              1 Reply Last reply Reply Quote 0
              • B
                bren85 last edited by

                Good work Andre!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post