summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/controls/Private/BasicButton.qml10
-rw-r--r--tests/auto/controls/data/tst_button.qml68
2 files changed, 75 insertions, 3 deletions
diff --git a/src/controls/Private/BasicButton.qml b/src/controls/Private/BasicButton.qml
index f20d476f..188e35ff 100644
--- a/src/controls/Private/BasicButton.qml
+++ b/src/controls/Private/BasicButton.qml
@@ -182,14 +182,18 @@ Control {
hoverEnabled: true
enabled: !keyPressed
- onReleased: if (containsMouse) __action.trigger(button)
+ onReleased: {
+ if (containsMouse) {
+ if (button.checkable && !button.action && !(button.checked && button.exclusiveGroup))
+ button.checked = !button.checked
+ __action.trigger(button)
+ }
+ }
onExited: Tooltip.hideText()
onCanceled: Tooltip.hideText()
onPressed: {
if (activeFocusOnPress)
button.forceActiveFocus()
- if (button.checkable && !button.action && !(button.checked && button.exclusiveGroup))
- button.checked = !button.checked
}
Timer {
diff --git a/tests/auto/controls/data/tst_button.qml b/tests/auto/controls/data/tst_button.qml
index 3836951c..5aba4376 100644
--- a/tests/auto/controls/data/tst_button.qml
+++ b/tests/auto/controls/data/tst_button.qml
@@ -197,5 +197,73 @@ TestCase {
verify(!control.control3.activeFocus)
control.destroy()
}
+
+ SignalSpy {
+ id: checkSpy
+ signalName: "checkedChanged"
+ }
+
+ function test_checked() {
+ var button = Qt.createQmlObject('import QtQuick.Controls 1.1; Button { checkable: true }', container, '')
+
+ var checkCount = 0
+
+ checkSpy.clear()
+ checkSpy.target = button
+ verify(checkSpy.valid)
+ verify(!button.checked)
+
+ // stays unchecked on press
+ mousePress(button, button.width / 2, button.height / 2)
+ verify(button.pressed)
+ verify(!button.checked)
+ compare(checkSpy.count, checkCount)
+
+ // gets checked on release inside
+ mouseRelease(button, button.width / 2, button.height / 2)
+ verify(!button.pressed)
+ verify(button.checked)
+ compare(checkSpy.count, ++checkCount)
+
+ // stays checked on press
+ mousePress(button, button.width / 2, button.height / 2)
+ verify(button.pressed)
+ verify(button.checked)
+ compare(checkSpy.count, checkCount)
+
+ // stays checked on release outside
+ mouseMove(button, button.width * 2, button.height * 2)
+ mouseRelease(button, button.width * 2, button.height * 2)
+ verify(!button.pressed)
+ verify(button.checked)
+ compare(checkSpy.count, checkCount)
+
+ // stays checked on press
+ mousePress(button, button.width / 2, button.height / 2)
+ verify(button.pressed)
+ verify(button.checked)
+ compare(checkSpy.count, checkCount)
+
+ // gets unchecked on release inside
+ mouseRelease(button, button.width / 2, button.height / 2)
+ verify(!button.pressed)
+ verify(!button.checked)
+ compare(checkSpy.count, ++checkCount)
+
+ // stays unchecked on press
+ mousePress(button, button.width / 2, button.height / 2)
+ verify(button.pressed)
+ verify(!button.checked)
+ compare(checkSpy.count, checkCount)
+
+ // stays unchecked on release outside
+ mouseMove(button, button.width * 2, button.height * 2)
+ mouseRelease(button, button.width * 2, button.height * 2)
+ verify(!button.pressed)
+ verify(!button.checked)
+ compare(checkSpy.count, checkCount)
+
+ button.destroy()
+ }
}
}