Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Stylesheet not being applied to children of custom widget which subclasses QWidget
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 5.6k Views 1 Watching
  • 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 Offline
    B Offline
    bren85
    wrote on last edited by
    #1

    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
    0
    • B Offline
      B Offline
      bren85
      wrote on last edited by
      #2

      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
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        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
        0
        • B Offline
          B Offline
          bren85
          wrote on last edited by
          #4

          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
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bren85
              wrote on last edited by
              #6

              Good work Andre!

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved