aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickslider.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@gmail.com>2015-08-28 18:53:15 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-10-03 10:48:48 +0000
commit067e55185497c46412c8d5353b8c984514d53580 (patch)
tree973a5487ded2b2191bb4bf4150343435e0acf0a0 /src/templates/qquickslider.cpp
parentbbfcde37af5936c2929446e085c5f122ed8d8341 (diff)
Fix Slider position calculation to take paddings into account
When Slider had paddings set, the handle didn't follow the touch point / mouse cursor. The larger paddings were set, the more the handle was "off". Change-Id: I82d97092a2c3fc99cba108fe011a463a571e5507 Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickslider.cpp')
-rw-r--r--src/templates/qquickslider.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/templates/qquickslider.cpp b/src/templates/qquickslider.cpp
index dcac1799..c733fbb2 100644
--- a/src/templates/qquickslider.cpp
+++ b/src/templates/qquickslider.cpp
@@ -117,19 +117,18 @@ qreal QQuickSliderPrivate::positionAt(const QPoint &point) const
if (orientation == Qt::Horizontal) {
const qreal hw = handle ? handle->width() : 0;
const qreal offset = hw / 2;
- const qreal extent = q->width() - hw;
+ const qreal extent = q->availableWidth() - hw;
if (!qFuzzyIsNull(extent)) {
- const qreal pos = (point.x() - offset) / extent;
- if (isMirrored())
- return 1.0 - pos;
- return pos;
+ if (q->isMirrored())
+ return (q->width() - point.x() - q->rightPadding() - offset) / extent;
+ return (point.x() - q->leftPadding() - offset) / extent;
}
} else {
const qreal hh = handle ? handle->height() : 0;
const qreal offset = hh / 2;
- const qreal extent = q->height() - hh;
+ const qreal extent = q->availableHeight() - hh;
if (!qFuzzyIsNull(extent))
- return 1.0 - (point.y() - offset) / extent;
+ return (q->height() - point.y() - q->bottomPadding() - offset) / extent;
}
return 0;
}