aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-12-02 18:45:15 +0100
committerIvan Solovev <ivan.solovev@qt.io>2021-12-03 10:43:18 +0100
commit29dfaa92b9d56f5555b511756f5b8ee62aabc0bf (patch)
tree19b128f3d531e7aee2f05e1b37fe05d1479f0def
parent1c17ea330cd29bc05c0463d1e13978ac5dd84ee9 (diff)
RangeSlider: update handle positions when 'from' or 'to' value is changed
The RangeSlider's setTo() and setFrom() implementation was not updating the positions of the handles. This patch fixes it and aligns the behavior with the basic Slider. This commit is cherry-picked from qtdeclarative repo of the dev branch, because QuickControls2 were merged into that repo in Qt 6. Fixes: QTBUG-98482 Change-Id: I482c416f91be2b97af1d922305dfe6fc1f5bd573 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit 7ff266ff782b35817d3ecc1a08c3a54bd2c2aa88)
-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)