Customizing vertical and horizontal Scrollbars at the same time with css

  • Hello!

    I have a widget inside of a QScrollArea and I want to customize the ScrollBars with css. When only one ScrollBar is enabled, the css works fine but when both are enabled, the sub-page and add-page controls lose their css. Anyone know why this is happening and how I can work around it? Any help would be much appreciated.

  • Moderators

    Can you show some code that gives you trouble?
    I checked and it seems to work fine:

    scrollArea->setStyleSheet( "QScrollBar { border: none; }"
    "QScrollBar::sub-page:horizontal { background-color: red; }"
    "QScrollBar::add-page:horizontal { background-color: green; }"
    "QScrollBar::sub-page:vertical { background-color: blue; }"
    "QScrollBar::add-page:vertical { background-color: yellow; }"

    The result is:
    ! example)!

  • when I set it to transparent it doesn't behave like this... It gives a grayish color like the normal color of a widget... Code is irrelevant because it works when only one of the scrollbars is visible...

    @QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {
    background: transparent;

    QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
    background: transparent;

  • Moderators

    Ok, I get what you mean, transparency works a little different.
    The add-page and sub-page become transparent, but they are "on top" of the QScrollBar, so it's default background is visible (gray). Also, the scrollbars are not "on top" of the scroll area content, they are beside it, so to get a common background for content and scrollbars you need to set it on the QScrollArea itself, and give the content transparent background.

    QScrollArea { background-color: red; }

    #scrollAreaWidgetContents { background-color: transparent; }

    QScrollBar { background-color: transparent; }

    QScrollBar::add-page { background-color: transparent; }
    ! example 2)!

Log in to reply