Search code examples
c++macosqtstylesheet

QScrollArea transparent background on MacOS X


I have a problem with making contents of QScrollArea to not draw a background.

So here is the initial picture, when I apply no stylesheet: enter image description here You can see, that the contents of scroll area are darker then the overall frame.

I have found the stylesheet that I can apply to scroll area, so the background is transparent. Here's the stylesheet I use:

QScrollArea { background: transparent; }
QScrollArea > QWidget > QWidget { background: transparent; }

Problem is that when I do that, the scrollbar of scrollarea gets messed up: enter image description here

You see? The scrollbar is now always visible and is ugly and transparent.

How can I make my stylesheet not to affect the scrollbar, while still applying it to the QScrollArea? Or what different stylesheet should I apply instead?


Solution

  • try to set an object name for the scroll area viewport:

    pScrollArea->viewport()->setObjectName("myViewport");
    

    then address it using the hashtag property in the stylesheet (also add the groupbox since the way I see it in your screenshot, your goal is to make them transparent as well):

    QScrollArea, #myViewport, QGroupBox { 
      background: transparent;
    }