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?

有帮助吗?

解决方案 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.

其他提示

You should try

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

It works for me

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top