I want to design a QSlider, which in the design sheet looks like this:
The slider groove color is the same for all slider parts, regardless of the slider handle being in its centre. In the design sheet, if the slider handle is moved to the left or right, it looks like this:
AFAIK, it is possible to change the slider's add/sub-page colors using style sheets.
However, I do not know how to change it in such a way that the change is done from the center, both to the left and right part, instead of the slider's leftmost point.
How could I achieve this?



Using A Stylesheet
While this is achievable using stylesheets, it is not recommended, the effort and complexity of the implementation is not worth the results, which are fragile and jagged. There are too many moving pieces for stylesheets to handle effectively while keeping a smooth, coherent look/behavior.
The basic idea is to use QLinearGradient for the sub-page/add-page sub controls, and separating the color stops with a small fraction (e.g, 0.00001). This achieves a segmented look.
The heavy work is done when trying to adjust the values each time the handle is moved.
Notice how the center is shaky:
That's without the handle, adding it makes things even more complicated:
Now there's a margin to take into account, and the center is off.
The details could possibly be corrected and finalised, but this approach is not worth it considering the results.
Using The Paint Event
A far better approach (in terms of implementation ease and end results) is using the paint event:
The center is stable, the margins are easier to calculate, and it works when added to layouts, unlike the stylesheets approach, which only gets worse:
For more about customizing QSlider: