Question

I'm trying to change the width of a vertical QScrollBar with a custom stylesheet like

QScrollBar:vertical 
{
     border: 2px solid grey;
     background: #32CC99;
     width: 10px;
     margin: 22px 0 22px 0;"
}
QScrollBar:vertical:hover { 
     background: red; 
     width: 25px ;
}

It doesn't work. Did I make any mistake? Can't we change the width of widget in run-time?

Was it helpful?

Solution 2

I don't think there is a way of doing this by using the stylesheets alone.

You could create your own scrollbar and override the enterEvent and leaveEvent and change the stylesheet there.

You could also install an event filter to your existing scrollbar (you can get your scrollbar by using the QAbstractScrollArea::verticalScrollBar() function) and listen to the same events and change the stylesheet there.

OTHER TIPS

You should try

QScrollBar::handle:hover {
    background: red; 
    width: 25px;
}

It works for me

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top