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)

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top