QScrollArea background color

  • How can I keep the (background) color of a widget after it is placed inside QScrollArea?
    The application contains only two background colors (defined by the system), and I would like to keep it that way. But, when I introduce a QScrollArea, everything inside it gets painted in colors that are completely different from the rest of the application, which destroys the look.
    I tried setting the palette of the scroll area, setting its backgroundRole, and several other things I found on the internet, but nothing seems to work. All I can do is apply one of the three colors that QScrollArea offers, but they are completely different from what the rest of the application uses.

    Note: I don't want to play with styleSheets as I would have to do the same for every single widget inside the scroll area. All I would like to do is prevent the QScrollArea from changing the color of widgets inside it - just add the scroll bars and nothing else.


  • Lifetime Qt Champion


    Can you post picture samples of what you are getting and what you are expecting ?

  • This post is deleted!

  • @SGaist

    I am not sure what the forum policy is when it comes to posting images, so here are the links:

    Preferred look: http://s13.postimg.org/5pysdlppj/color_Good_resized.jpg
    Obtained look: http://s16.postimg.org/6oh620o0l/color_Bad_resized.jpg

    Obtained look: Look at the left half of the window, there are two vertical tabs called Chooser and Adjuster. It's a QTabWidget and both tabs are QFrame. In the picture, Chooser is the active tab and it contains checkboxes, combo boxes etc. I need horizontal scrolling here, so there is a QScrollArea there and, in this picture, it draws everything inside it in white (QPalette::Base). If I try QPalette::AlternateBase or QPalette::Window, the background becomes dark - either similar to the color of the inactive tab or even darker, both being very bad choices for different reasons. What I want is shown in the preferred look image, which is without QScrollArea.

    I hope this helps.

  • Lifetime Qt Champion

    That's indeed a strange interaction. Can you reproduce that with a small set of widgets ?

    Also why put them in QFrames ? A QGroupBox would be a better fit for that.

  • @SGaist

    I am not first to ask about this problem, but here it goes: http://s24.postimg.org/r6wo5opw5/scroll_Test.png
    It is a QTabWidget whose tab is a QFrame, which has a QScrollArea inside. As you can see, It is darker in color than the background of its parent QFrame.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.