implement mouse release handler
This commit is contained in:
parent
07720c5f66
commit
fc253ecd11
|
@ -76,3 +76,16 @@ void Slider::mouseMoveEvent(QMouseEvent *event)
|
|||
|
||||
QAbstractSlider::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void Slider::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
Q_D(Slider);
|
||||
|
||||
QRect track(d->trackGeometry().adjusted(-2, -2, 2, 2));
|
||||
|
||||
if (track.contains(event->pos())) {
|
||||
setValue(d->valueFromPosition(event->pos()));
|
||||
}
|
||||
|
||||
QAbstractSlider::mouseReleaseEvent(event);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
protected:
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
const QScopedPointer<SliderPrivate> d_ptr;
|
||||
|
||||
|
|
|
@ -111,6 +111,24 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
int valueFromPosition(const QPoint &pos) const
|
||||
{
|
||||
Q_Q(const Slider);
|
||||
|
||||
const int span = Qt::Horizontal == orientation
|
||||
? q->rect().width() - THUMB_OUTER_SIZE
|
||||
: q->rect().height() - THUMB_OUTER_SIZE;
|
||||
|
||||
const int position = Qt::Horizontal == orientation ? pos.x() : pos.y();
|
||||
|
||||
return Style::sliderValueFromPosition(
|
||||
q->minimum(),
|
||||
q->maximum(),
|
||||
position - THUMB_OUTER_SIZE/2,
|
||||
span,
|
||||
false);
|
||||
}
|
||||
|
||||
Slider *const q_ptr;
|
||||
|
||||
Qt::Orientation orientation;
|
||||
|
|
|
@ -145,7 +145,5 @@ void SliderExamples::flip()
|
|||
|
||||
void SliderExamples::updateSliderValue()
|
||||
{
|
||||
int n = _edit2->text().toInt();
|
||||
qDebug() << n;
|
||||
_slider2->setValue(n);
|
||||
_slider2->setValue(_edit2->text().toInt());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue