Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to apply style sheet to nested properties?



  • If we want the property to apply only to one specific instance, we can specify the object name in the style sheet.

    // the style sheet will only apply to the object called evilButton

    QPushButton#evilButton { background-color: red }
    

    What if I want the following property to also be used by a specific object? I noticed that if I wrote QScrollBar#evilScroller:vertical, the style isn't applied at all.

    QScrollBar:vertical{
          background:palette(base);
          border-top-right-radius:2px;
          border-bottom-right-radius:2px;
          width:16px;
          margin:0px;
        }
    


  • You have a QScrollBar named "evilButton"?



  • @Bonnie hahaha! Nope, sorry it's a bad example. I renamed it now. But I realize that the scrollers are automatically created by QGraphicScene and I've only set the window's objectName but not the scroller's object name. I don't know if I can actually set the scrollers' object names manually as QGraphicScene doesn't seem to have a function to access it's scrollers.



  • That's what I think.
    We usually don't create a QScrollBar. They come with other container widgets.
    So you probably did not use the right object name.
    If it really has a object name of "evilScroller", I think the style sheet should work.


  • Lifetime Qt Champion

    Hi
    I assume you mean on QGraphicsView as QGraphicScene is nonvisual so I will be hugely surprised if it has scrollbars :)

    In any case, if i set on the view, its used when scrollbar shows up
    alt text


Log in to reply