QScrollBar button size

418 Views Asked by At

I'm creating a GUI in QtDesigner and did some styling on the window itself made everything have font size 30pt and QScrollBars width and height (vertical and horizontal respectively) 90px. For simplicity i'll continue with vertical scrollbars, but translate everything to horizontal ones too. Now the buttons at the ends of the scrollbar are slim as they heights remained the same (and i presume the slider itself has minimum height lower than 90px). Styling those buttons did not yield any results. Could someone please tell me, what should i do to make those buttons (and the minimum slider height) bigger, so that it could be used on a 1024x600, 7" touch monitor? Qt version 5.11.3, and using python, PySide2. Thanks

2

There are 2 best solutions below

0
On

To set the width of all vertical scrollbars of widget w and its children:

w.setStyleSheet('QScrollBar:vertical {width: 40px;}')

for the height of horizontal ones:

w.setStyleSheet('QScrollBar:horizotal {height: 40px;}')

2
On

You can style the QScollbars buttons size by the css selectors QScrollBar::add-line:vertical and QScrollBar::sub-line:vertical. I apply the style on Bars like this:

QScrollBar:vertical
{
    border: 1px solid grey;
    background: white;
    width: 50px;
    margin: 52px 0px 52px 0px;
}
QScrollBar::handle:vertical
{
    background: grey;
}
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical
{
    background: none;
}
QScrollBar::add-line:vertical
{
    height: 50px;
    subcontrol-position: bottom;
    subcontrol-origin: margin;
}
QScrollBar::sub-line:vertical
{
    height: 50px;
    subcontrol-position: top;
    subcontrol-origin: margin;
}

Further styling on add-line and sub-line (like adding borders...) may remove the default scrollbar arrows that is why I left this out.