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: 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:
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?
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;
}
The problem is that QScrollBar is a subclass of QWidget, so just target the viewport with that rule:
pScrollArea->setStyleSheet("QScrollArea { background: transparent; }");
pScrollArea->viewport()->setStyleSheet(".QWidget { background: transparent; }");
Notice the dot before QWidget, so to not target any children of the viewport (ie, any viewport content that's a QWidget subclass).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.