aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickrangeslider.cpp8
-rw-r--r--tests/auto/controls/data/tst_rangeslider.qml37
2 files changed, 45 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp
index 7aee2109..25542fcc 100644
--- a/src/quicktemplates2/qquickrangeslider.cpp
+++ b/src/quicktemplates2/qquickrangeslider.cpp
@@ -665,6 +665,10 @@ void QQuickRangeSlider::setFrom(qreal from)
if (isComponentComplete()) {
d->first->setValue(d->first->value());
d->second->setValue(d->second->value());
+ auto *firstPrivate = QQuickRangeSliderNodePrivate::get(d->first);
+ auto *secondPrivate = QQuickRangeSliderNodePrivate::get(d->second);
+ firstPrivate->updatePosition(true);
+ secondPrivate->updatePosition();
}
}
@@ -693,6 +697,10 @@ void QQuickRangeSlider::setTo(qreal to)
if (isComponentComplete()) {
d->first->setValue(d->first->value());
d->second->setValue(d->second->value());
+ auto *firstPrivate = QQuickRangeSliderNodePrivate::get(d->first);
+ auto *secondPrivate = QQuickRangeSliderNodePrivate::get(d->second);
+ firstPrivate->updatePosition(true);
+ secondPrivate->updatePosition();
}
}
diff --git a/tests/auto/controls/data/tst_rangeslider.qml b/tests/auto/controls/data/tst_rangeslider.qml
index d645ec70..42f5bad5 100644
--- a/tests/auto/controls/data/tst_rangeslider.qml
+++ b/tests/auto/controls/data/tst_rangeslider.qml
@@ -159,6 +159,43 @@ TestCase {
compare(control.first.position, 0.5)
}
+ function test_setToFromUpdatesHandles() {
+ var control = createTemporaryObject(sliderComponent, testCase, { from: 0, to: 100, "first.value": 50, "second.value": 75 })
+ verify(control)
+
+ let firstPos = control.first.position
+ let secondPos = control.second.position
+
+ var firstPosChangesSpy = signalSpy.createObject(control, {target: control.first, signalName: "positionChanged"})
+ verify(firstPosChangesSpy.valid)
+
+ var secondPosChangesSpy = signalSpy.createObject(control, {target: control.second, signalName: "positionChanged"})
+ verify(secondPosChangesSpy.valid)
+
+ // Increasing the 'to' value, so the positions of the handles should be
+ // moved to the left (become smaller)
+ control.to = 200;
+ compare(firstPosChangesSpy.count, 1)
+ compare(secondPosChangesSpy.count, 1)
+ verify(control.first.position < firstPos)
+ verify(control.second.position < secondPos)
+
+ // resetting the values
+ control.to = 100
+ firstPosChangesSpy.clear()
+ secondPosChangesSpy.clear()
+ firstPos = control.first.position
+ secondPos = control.second.position
+
+ // Decreasing the 'from' value, so the positions of the handles should
+ // be moved to the right (become larger)
+ control.from = -100
+ compare(firstPosChangesSpy.count, 1)
+ compare(secondPosChangesSpy.count, 1)
+ verify(control.first.position > firstPos)
+ verify(control.second.position > secondPos)
+ }
+
function test_setValues() {
var control = createTemporaryObject(sliderComponent, testCase)
verify(control)