Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

You must change entire QSlider to manage such things. Otherwise it will fallback into default Mac OS X painting style. So you must change border and background of QSlider and handle itself. Take a look at this example

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top