Search code examples
qtstylesheethandleqt4.7qslider

How to use stylesheet to customize handle of QSlider on MacOS


On MacOS 10.6, the default handle of QSlider is a ball, if a QSlider has ticks, then the handle changes its appearence (one side arrow shape), I want this kind of handle, but I don't like the ticks Qt provides. So, I'd like to store that picture of handle as qrc resource and use stylesheet to customize the look of qslider. That's the only way I can figure out.

Could anyone tell me how to write the style sheet, I mean that everything keep the same but only the handle changes.

BTW, there's another question. For a default QSlider on MacOS, the handle can't reach to the most left and most right position of the groove, how to use stylesheet to adjust it?


Solution

  • Add an image of the handle you want in your resources (.qrc) file. It should be quite easy to Photoshop the handle you like (or use some other program). Then try adding this in your code

    setStyleSheet("QSlider::handle {image: url(:/resources/image.png);}");
    

    You might need to experiment a bit with the padding and margins to get the slider positioned the way you want.