aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickswitch.cpp8
-rw-r--r--src/quicktemplates2/qquickswitchdelegate.cpp8
-rw-r--r--tests/auto/controls/data/tst_switch.qml17
-rw-r--r--tests/auto/controls/data/tst_switchdelegate.qml17
4 files changed, 46 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickswitch.cpp b/src/quicktemplates2/qquickswitch.cpp
index fa08a1d8..5e3d6418 100644
--- a/src/quicktemplates2/qquickswitch.cpp
+++ b/src/quicktemplates2/qquickswitch.cpp
@@ -186,10 +186,14 @@ void QQuickSwitch::mirrorChange()
void QQuickSwitch::nextCheckState()
{
Q_D(QQuickSwitch);
- if (keepMouseGrab())
+ if (keepMouseGrab()) {
setChecked(d->position > 0.5);
- else
+ // the checked state might not change => force a position update to
+ // avoid that the handle is left somewhere in the middle (QTBUG-57944)
+ checkStateSet();
+ } else {
QQuickAbstractButton::nextCheckState();
+ }
}
void QQuickSwitch::checkStateSet()
diff --git a/src/quicktemplates2/qquickswitchdelegate.cpp b/src/quicktemplates2/qquickswitchdelegate.cpp
index 81e282d9..e659b927 100644
--- a/src/quicktemplates2/qquickswitchdelegate.cpp
+++ b/src/quicktemplates2/qquickswitchdelegate.cpp
@@ -191,10 +191,14 @@ void QQuickSwitchDelegate::mirrorChange()
void QQuickSwitchDelegate::nextCheckState()
{
Q_D(QQuickSwitchDelegate);
- if (keepMouseGrab())
+ if (keepMouseGrab()) {
setChecked(d->position > 0.5);
- else
+ // the checked state might not change => force a position update to
+ // avoid that the handle is left somewhere in the middle (QTBUG-57944)
+ checkStateSet();
+ } else {
QQuickItemDelegate::nextCheckState();
+ }
}
void QQuickSwitchDelegate::checkStateSet()
diff --git a/tests/auto/controls/data/tst_switch.qml b/tests/auto/controls/data/tst_switch.qml
index f3843cf7..52d2d7fc 100644
--- a/tests/auto/controls/data/tst_switch.qml
+++ b/tests/auto/controls/data/tst_switch.qml
@@ -187,6 +187,23 @@ TestCase {
compare(control.pressed, false)
verify(spy.success)
+ // release in the middle
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }],
+ "pressed"]
+ mousePress(control, 0, 0, Qt.LeftButton)
+ compare(control.pressed, true)
+ verify(spy.success)
+ mouseMove(control, control.width / 4, control.height / 4, 0, Qt.LeftButton)
+ compare(control.pressed, true)
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }],
+ "released",
+ "clicked"]
+ mouseRelease(control, control.width / 4, control.height / 4, Qt.LeftButton)
+ compare(control.checked, false)
+ compare(control.pressed, false)
+ tryCompare(control, "position", 0) // QTBUG-57944
+ verify(spy.success)
+
// right button
spy.expectedSequence = []
mousePress(control, control.width / 2, control.height / 2, Qt.RightButton)
diff --git a/tests/auto/controls/data/tst_switchdelegate.qml b/tests/auto/controls/data/tst_switchdelegate.qml
index 4a5d711f..bb4b9d6a 100644
--- a/tests/auto/controls/data/tst_switchdelegate.qml
+++ b/tests/auto/controls/data/tst_switchdelegate.qml
@@ -183,6 +183,23 @@ TestCase {
compare(control.pressed, false)
verify(spy.success)
+ // release in the middle
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }],
+ "pressed"]
+ mousePress(control.indicator, 0, 0, Qt.LeftButton)
+ compare(control.pressed, true)
+ verify(spy.success)
+ mouseMove(control.indicator, control.indicator.width / 2 - 1, 0)
+ compare(control.pressed, true)
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }],
+ "released",
+ "clicked"]
+ mouseRelease(control.indicator, control.indicator.width / 2 - 1, 0, Qt.LeftButton)
+ compare(control.checked, false)
+ compare(control.pressed, false)
+ tryCompare(control, "position", 0) // QTBUG-57944
+ verify(spy.success)
+
// right button
spy.expectedSequence = []
mousePress(control, control.width / 2, control.height / 2, Qt.RightButton)