I want to draw a tick mark for a qslider in paintEvent, so I should get the exact position of each tick mark. As you know, the handle of slider takes some space, so the first tick mark does not sit at the left/top position of the slider, there is offset of several pixels. Same thing happens to the last tick mark which indicates the maximum value. I want to know how many pixels of the space? (On win and mac, the handle are not in the same width)
Asked
Active
Viewed 1,180 times
1 Answers
1
If you have not yet done so, download the Qt source code and copy how they do it. You will want to look in the various Q...Style
classes, i.e QMacStyle
, QWindowsXPStyle
, etc. Some of the key calculations come from:
- QStyle::sliderPositionFromValue() method
- QStyle::pixelMetric(QStyle::PM_SliderTickmarkOffset, ...)
Look in the various drawComplexControl
methods for case CC_Slider:
, where slider controls are drawn. In the Qt 4.7 code, this starts on line 2699 in qwindowsxpstyle.cpp, for example.

Dave Mateer
- 17,608
- 15
- 96
- 149
-
Thanks you very much, this piece of advice helps me a lot. – Royt Mar 27 '12 at 05:55