Results 1 to 7 of 7

Thread: QScrollArea misbehaving background style

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QScrollArea misbehaving background style

    Hi there.

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

    Qt Code:
    1. QScrollArea, QAbstractScrollArea, QWidget[isScrollArea="true"] {
    2. background-color: black;
    3. background: black;
    4. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. background-color: black;
    2. background: black;
    3. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScrollArea misbehaving background style

    The "main part" is the viewport of the scroll area and it is a separate widget. Try with:
    css Code:
    1. QScrollArea > QWidget {
    2. background-color: black;
    3. }
    To copy to clipboard, switch view to plain text mode 

    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).

  3. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea misbehaving background style

    That doesn't do it either. However, it seems to be influenced by

    Qt Code:
    1. QFrame[isScrollArea="true"] {
    2. background-color: black;
    3. }
    To copy to clipboard, switch view to plain text mode 

    given the isScrollArea property is set.

  4. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QScrollArea misbehaving background style

    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.

  5. #5
    Join Date
    Jul 2010
    Posts
    1
    Thanked 4 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QScrollArea misbehaving background style

    You can change QScrollArea's background color by using QWidget .
    By using:
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    you can set the background color or text color etc.

    Ex:
    Qt Code:
    1. {
    2. background-color:white;
    3. color:black;
    4. }
    To copy to clipboard, switch view to plain text mode 

  6. The following 4 users say thank you to bekoturanci for this useful post:

    Cruz (27th April 2011), leninbooter (31st December 2011), RyanR (21st April 2021), zeFree (10th December 2011)

  7. #6
    Join Date
    Jan 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QScrollArea misbehaving background style

    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*/
    }

  8. #7

    Default Re: QScrollArea misbehaving background style

    Thanks a lot for sharing your solution. I know it's an older post but saves me a lot of time when solving it.

Similar Threads

  1. Background Style Disables QScrollBar "Drag" Action
    By brent99 in forum Qt Programming
    Replies: 1
    Last Post: 3rd June 2008, 21:16
  2. Transparent background Style
    By Lele in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2006, 13:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.