Stylesheet for scrollbar in QScrollArea
-
Hello, how can i set qss style for scrollbar in QScrollArea.
What i have tried..
In qss for QScrollArea i set code from documentation:QScrollBar:vertical { border: 2px solid grey; background: #32CC99; height: 15px; margin: 0px 20px 0 20px; } QScrollBar::handle:vertical { background: white; min-width: 20px; } QScrollBar::add-line:vertical { border: 2px solid grey; background: #32CC99; width: 20px; subcontrol-position: right; subcontrol-origin: margin; } QScrollBar::sub-line:vertical { border: 2px solid grey; background: #32CC99; width: 20px; subcontrol-position: left; subcontrol-origin: margin; }
But nothing.. scrollbar in QScrollArea still have standard style.
-
Hi,
How are you setting that style sheet ?
How are you creating your QScrollArea ?What version of Qt are you using ?
On what platform ? -
Below is my working code cor Vertical Scroll Bar
QScrollBar:vertical {border-color: #424242;border-width: 1px;border-style: solid; background-color: #32CC99;width: 25px;margin: 21px 0 21px 0; QScrollBar::handle:vertical {background-color:white ;min-height: 25px;} QScrollBar::add-line:vertical {border: 2px solid black;background-color: #32CC99; height: 25px;subcontrol-position: bottom;subcontrol-origin: margin;} QScrollBar::sub-line:vertical {border: 2px solid black;background-color: #32CC99; height: 25px;subcontrol-position: top;subcontrol-origin: margin;}
the code you are using is for Horizontal scroll bar i think so, as for vertical scroll bar margin should be
margin: 20px 0px 20px 0px;
Hope this helps .
-
Hello, I have same trouble.
I use QtDesigner to create .ui files and VS Code to run PySide6 code.
This is my QSS code.QScrollBar:vertical { border: none; background: rgb(75, 75, 75); width: 14px; margin: 15px 0 15px 0; border-radius: 0px; }
I set style sheet and create QScrollArea in QtDesigner.
Preview in QtDesigner can show this options on my QScrollBar, but when I run my Python code with this form I see default scroll. Where did I go wrong? -
@NikM Hi, did you fix the error, even I see the customized bar in designer but it rolls back to default style when I preview the widget. I saw a post on stackoverflow too: https://stackoverflow.com/questions/66557285/my-pyqt5-custom-scrollbar-stylesheet-doesnt-apply but, didn't quite understand what parent element meant.