Important: Please read the Qt Code of Conduct -

Set style for QScrollArea's viewport

  • I'm trying to style the viewport of a custom QScrollArea as follows:

    @setStyleSheet("QScrollArea > QWidget > QWidget{background:transparent;}");@

    Which successfully styles the vieport, but also the scroll bar (which I don't want to do). So I tried the following to only style the viewport and not the bar:

    @setStyleSheet("QScrollArea > QWidget > .QWidget{background:transparent;}");@

    But that didn't do anything at all. So I tried to style the viewport directly:


    Which works, but it also styles all the child widgets in the viewport, so I tried:


    Which again didn't style it at all. So my question: is the viewport actually a QWidget or is it one of QWidget's subclasses, since I'm unable to style it by using .QWidget. If it is a QWidget, what am I doing wrong, why doesn't the viewport style (without affecting the child widgets and the scroll bar).

Log in to reply