I am trying to change the background color of the scrollers in my QGraphicsView
using stylesheet. But it also changes the handler's shape from a nice rounded bar to an ugly rectangle. Is it possible to retain the original shape? Here is the code:
QString style = R"( QScrollBar:vertical {
background: rgb(61,61,61);
}
QScrollBar::handle:vertical {
background: rgb(119,119,119);
min-width: 20px;
}
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
background: none;
})";
myGraphicsView->setStyleSheet(style);
This is the original look:
This is after setting the stylesheet (now the handle is rectangular):
A bit late for the OP, but for others...
I would try adding more specific style for your handle.
I have the following in the application-level style-sheet that I managed to get working last year
I suspect that with no style applied, the system default "native" style is used for the whole scrollbar. If you apply one element of style, then a (simple) default style is drawn explicitly, and your style is applied to that. So, if you only specify the background colour for your scrollbar, you'll get the default style for the handle. So, you want to specify most components of the handle to get it to look something like the native system one - border-style, color, border-radius...
I purged scroll bars from my app actually, and now I don't remember what happens if you don't specify the border - but it must have been pretty ugly ! (my aesthetic standards are minimal...)