How can the handle of a QScrollBar be styled and made scalable?
I have a styled QScrollBar on my table which uses an image for the handle of the scroll bar. The handle is rounded at the edges (with transparency in the image around the edges, of course). Now the problem is that i can't seem to make it re-size nicely. It's a vertical scroll-bar, so the only way I found to work so far is to set:
background-image: url(:/res/img/scrollbar-vhandle.png);
background-repeat: repeat-y;
in my stylesheet. Which does what it's supposed to, only my scroll bar looks ugly, especi开发者_StackOverflow中文版ally because of the rounded corners.
The image could be 'stretched' nicely by repeating a 1px high line from it's y-center. But even y-stretching should be ok. I just can't find a good way to do it. Something like a QPushButton, where 9 images can be used for 1 button in order to scale would work, but unfortunately doesn't seem like it does.
So, if anyone can let me know if it's a way to do it through stylesheets (or deriving from QScrollBar, and repainting the handle) i'd appreciate it very much.
If you need more info, please let me know.
Well, as you say, you could inherit from the scrollbar and overload the paintEvent function. Therein you can pretty much to whatever you want, for example compute your new pixmap by repeating that one line and painting it. There are actually a couple of functions in QPixmap that should make this relatively easy.
精彩评论