Pregunta

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?

¿Fue útil?

Solución 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.

Otros consejos

You should try

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

It works for me

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top