summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2017-11-30 10:48:18 +0100
committerAndy Shaw <andy.shaw@qt.io>2018-04-17 09:06:20 +0000
commit0689a8256c0a21087c01fff3998fd3b606a5ac4c (patch)
tree06fc65bac9ec9570513b7f52b0028e4cc3e81691
parent71beceb772dedfcaa30eda8ce2ed146e835b59f9 (diff)
downloadqtquickcontrols-0689a8256c0a21087c01fff3998fd3b606a5ac4c.tar.gz
Slider: don't break the binding on value when using the mouse wheel
When the wheel was used it could cause any binding on value to be broken since it was updated directly. Going via range.position ensures this is not the case. Change-Id: Ic041ea911cee68de34f5c4e184cf8460f5e002da Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/controls/Slider.qml4
-rw-r--r--tests/auto/controls/data/tst_slider.qml33
2 files changed, 35 insertions, 2 deletions
diff --git a/src/controls/Slider.qml b/src/controls/Slider.qml
index e290640e..07ad74c4 100644
--- a/src/controls/Slider.qml
+++ b/src/controls/Slider.qml
@@ -331,14 +331,14 @@ Control {
onVerticalWheelMoved: {
if (verticalDelta !== 0) {
var delta = Math.abs(verticalDelta)*step > stepSize ? verticalDelta*step : verticalDelta/Math.abs(verticalDelta)*stepSize
- value -= delta * (inverted ? 1 : -1)
+ range.position = range.positionForValue(value - delta * (inverted ? 1 : -1))
}
}
onHorizontalWheelMoved: {
if (horizontalDelta !== 0) {
var delta = Math.abs(horizontalDelta)*step > stepSize ? horizontalDelta*step : horizontalDelta/Math.abs(horizontalDelta)*stepSize
- value += delta * (inverted ? 1 : -1)
+ range.position = range.positionForValue(value + delta * (inverted ? 1 : -1))
}
}
}
diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml
index e95d26d9..f6435314 100644
--- a/tests/auto/controls/data/tst_slider.qml
+++ b/tests/auto/controls/data/tst_slider.qml
@@ -439,5 +439,38 @@ Item {
control.destroy();
}
+
+ Component {
+ id: mouseWheelSlider
+ Slider {
+ property real boundValue: 10
+ width: 300
+ height: 50
+ minimumValue: 0
+ maximumValue: 200
+ stepSize: 2
+ value: boundValue
+ }
+ }
+
+ function test_mouseWheelWithValueBinding() {
+ var slider = createTemporaryObject(mouseWheelSlider, container)
+ slider.forceActiveFocus()
+
+ var defaultScrollSpeed = 20.0
+ var mouseStep = 15.0
+ var deltatUnit = 8.0
+ var mouseRatio = deltatUnit * mouseStep / defaultScrollSpeed;
+ var sliderDeltaRatio = 1; //(slider.maximumValue - slider.minimumValue)/slider.width
+ var ratio = mouseRatio / sliderDeltaRatio
+
+ compare(slider.value, 10)
+
+ mouseWheel(slider, 5, 5, -20 * ratio, 0)
+ compare(slider.value, 24)
+
+ slider.boundValue = 50
+ compare(slider.value, 50)
+ }
}
}