Royt
Royt

Reputation: 199

How to get the position of the first and the last tick mark in a Qslider?

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)

Upvotes: 0

Views: 1253

Answers (1)

Dave Mateer
Dave Mateer

Reputation: 17946

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.

Upvotes: 1

Related Questions