You can actually achieve that with only style sheets and the border-image
property on the groove
subcontrol.
For example with a border image like this:
To better see what goes where, B is 10 pixel wide, the space is 2, and A is 12 pixel wide.
QSlider::groove {
border-image: url(:/slider-decoration.png) 0 12 0 10;
border-left: 10px solid transparent;
border-right: 12px solid transparent;
}
QSlider::handle {
width: 8px;
background-color: green;
}
Which gives you what you expect:
This solution has a small problem, though. The mouse ignores the presence of the border, and there is an offset near both ends between the handle position and the mouse position. So, to avoid that, the handle has to go all the way to either side, but we add a transparent border to it that make it look like it stops just before the image borders:
QSlider::groove {
border-image: url(:/slider-decoration.png) 0 12 0 10;
border-left: 10px;
border-right: 12px;
}
QSlider::handle {
width: 8px;
/* add borders to the handle that will sit above the groove border */
border-right: 10px solid transparent;
border-left: 12px solid transparent;
/* negative margins to allow the handle borders
to go past the groove borders */
margin-right: -10px;
margin-left: -12px;
background-color: green;
/* make the background color fill the content, not the border */
background-clip: content;
}