From 9300275ae52c0451e633d68e25bf85f98723e34b Mon Sep 17 00:00:00 2001 From: laserpants Date: Sat, 30 Apr 2016 20:27:55 +0300 Subject: [PATCH] compensate space around slider for scaling of handle --- components/slider.cpp | 15 ++++++++++++--- components/slider.h | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/components/slider.cpp b/components/slider.cpp index 4d02293..a151520 100644 --- a/components/slider.cpp +++ b/components/slider.cpp @@ -102,16 +102,25 @@ void Slider::paintEvent(QPaintEvent *event) ? QRect(x-1, 0, 2, height()) : QRect(0, y-1, width(), 2); + const QSize s = _handle->sizeHint(); + QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(QColor(0, 0, 0)); + + if (Qt::Horizontal == _orientation) { + r.adjust(s.width()/2, 0, -s.width()/2, 0); + } else { + r.adjust(0, s.height()/2, 0, -s.height()/2); + } painter.fillRect(r, brush); painter.save(); - brush.setColor(QColor(255, 0, 0)); + brush.setColor(Qt::red); + const QPoint p = Qt::Vertical == _orientation - ? QPoint(width(), _handle->y()) - : QPoint(_handle->x(), height()); + ? QPoint(width(), _handle->y()+s.height()/2) + : QPoint(_handle->x()+s.width()/2, height()); painter.fillRect(r.intersected(QRect(QPoint(0, 0), p)), brush); painter.restore(); diff --git a/components/slider.h b/components/slider.h index 4ff0155..8d51a8f 100644 --- a/components/slider.h +++ b/components/slider.h @@ -17,7 +17,7 @@ public: explicit Handle(Slider *slider); ~Handle(); - inline QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(24, 24); } // *_scaleFactor; } + inline QSize sizeHint() const Q_DECL_OVERRIDE { return QSize(20, 20); } inline void setRelativePosition(const QPoint &pos) { setPosition(_offset + pos); }