qt widen QScrollBar when hover using StyleSheet

2019-08-20 18:29发布

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条回答
太酷不给撩
2楼-- · 2019-08-20 18:57

You should try

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

It works for me

查看更多
Root(大扎)
3楼-- · 2019-08-20 19:05

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.

查看更多
登录 后发表回答