20 #include <QStylePainter> 21 #include <QStyleOptionSlider> 29 m_tickColor(Qt::white)
35 QStylePainter p(
this);
36 QStyleOptionSlider opt;
37 initStyleOption(&opt);
39 QRect handle = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle,
this);
43 int interval = tickInterval();
46 interval = pageStep();
49 if (tickPosition() != NoTicks)
51 for (
int i = minimum();
i <= maximum();
i += interval)
53 int x = roundf((
double)((
double)((
double)(
i - this->minimum()) / (
double)(this->maximum() - this->minimum())) * (
double)(this->width() - handle.width()) + (
double)(handle.width() / 2.0))) - 1;
56 if (tickPosition() == TicksBothSides || tickPosition() == TicksAbove)
58 int y = this->rect().top();
59 p.drawLine(x, y, x, y + h);
61 if (tickPosition() == TicksBothSides || tickPosition() == TicksBelow)
63 int y = this->rect().bottom();
64 p.drawLine(x, y, x, y - h);
71 opt.subControls = QStyle::SC_SliderGroove;
72 p.drawComplexControl(QStyle::CC_Slider, opt);
75 opt.subControls = QStyle::SC_SliderHandle;
76 p.drawComplexControl(QStyle::CC_Slider, opt);
virtual void paintEvent(QPaintEvent *ev)
TickedSlider(QWidget *parent=0)