PDA

View Full Version : QScrollArea misbehaving background style



Cruz
19th January 2009, 17:56
Hi there.

I'm trying to style a QScrollArea with an external style sheet and it doesn't work right.



QScrollArea, QAbstractScrollArea, QWidget[isScrollArea="true"] {
background-color: black;
background: black;
}


With this style I can only influence a thin border of the scroll area. The background color of the main part only reacts to this:



QWidget {
background-color: black;
background: black;
}


As you can see I also tried using QAbstractScrollArea and even a QWidget style reacting to the dynamic property "isScrollArea". Is anyone else having the same problem?

wysota
20th January 2009, 01:29
The "main part" is the viewport of the scroll area and it is a separate widget. Try with:
QScrollArea > QWidget {
background-color: black;
}

Or don't use style sheets at all - you can manipulate the palette of the viewport. In case of this widget this is very easy (remember to set autoFillBackground property to true).

Cruz
20th January 2009, 08:38
That doesn't do it either. However, it seems to be influenced by



QFrame[isScrollArea="true"] {
background-color: black;
}


given the isScrollArea property is set.

Cruz
20th January 2009, 08:57
I can't find a way to influence that viewport directly. There is nothing said about it in the class reference. In Designer I can set the palette of the Widget that QScrollArea is derived from and that would do the trick, if some other styles (QFrame, QWidget) wouldn't override it. Even if autoFillBackground is set.

Completelely swtiching from style sheets to a palette based approach would be too big of an impact for this project. I will rather try to get the QScrollAreas under control with targeted QFrame[isScrollArea="true"] styles.

Style sheets would be such a nice way to decorate your gui. It's really a shame that there is so many little problems with it.

bekoturanci
23rd July 2010, 10:38
You can change QScrollArea's background color by using QWidget .
By using:
QScrollArea QWidget you can set the background color or text color etc.

Ex:


QScrollArea QWidget
{
background-color:white;
color:black;
}

Chris606
18th January 2016, 07:41
For anyone else with the same problem this is how i fixed it.

QAbstractScrollArea
{
background-color: transparent;
}
QWidget#scrollAreaWidgetContents{
background-color: transparent; /*or a colour*/
}

ludek.vodicka
7th March 2021, 21:46
Thanks a lot for sharing your solution. I know it's an older post but saves me a lot of time when solving it.