summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-01-23 10:45:54 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-01-23 11:59:36 +0000
commit69eaa4052c5d5e8f4ac2f87e2ef3362c5d429e64 (patch)
treeec9a48f63a25d99824dd9ae7ffb6a88562b8b5b4
parentc1b1e9a69a5770a59d0a4e59650c6487b9cd5439 (diff)
QQuickAbstractButton: don't leak space key events
Unlike mouse events, key events are not accepted by default. Key events must be accepted to avoid event propagation. Change-Id: I8d9217e6f18d56515470bef2507d462edd274ce2 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquickabstractbutton.cpp2
-rw-r--r--tests/auto/controls/data/tst_abstractbutton.qml36
2 files changed, 38 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp
index 6af8b00d..68a0a11b 100644
--- a/src/quicktemplates2/qquickabstractbutton.cpp
+++ b/src/quicktemplates2/qquickabstractbutton.cpp
@@ -496,6 +496,7 @@ void QQuickAbstractButton::keyPressEvent(QKeyEvent *event)
}
emit pressed();
+ event->accept();
}
}
@@ -512,6 +513,7 @@ void QQuickAbstractButton::keyReleaseEvent(QKeyEvent *event)
if (d->autoRepeat)
d->stopPressRepeat();
+ event->accept();
}
}
diff --git a/tests/auto/controls/data/tst_abstractbutton.qml b/tests/auto/controls/data/tst_abstractbutton.qml
index b785b7a1..157616d6 100644
--- a/tests/auto/controls/data/tst_abstractbutton.qml
+++ b/tests/auto/controls/data/tst_abstractbutton.qml
@@ -125,4 +125,40 @@ TestCase {
control.destroy()
}
+
+ Component {
+ id: keyCatcher
+ Item {
+ property int lastKeyPress: -1
+ property int lastKeyRelease: -1
+ Keys.onPressed: lastKeyPress = event.key
+ Keys.onReleased: lastKeyRelease = event.key
+ }
+ }
+
+ function test_keyEvents_data() {
+ return [
+ { tag: "space", key: Qt.Key_Space, result: -1 },
+ { tag: "backspace", key: Qt.Key_Backspace, result: Qt.Key_Backspace }
+ ]
+ }
+
+ function test_keyEvents(data) {
+ var container = keyCatcher.createObject(testCase)
+ verify(container)
+
+ var control = button.createObject(container)
+ verify(control)
+
+ control.forceActiveFocus()
+ verify(control.activeFocus)
+
+ keyPress(data.key)
+ compare(container.lastKeyPress, data.result)
+
+ keyRelease(data.key)
+ compare(container.lastKeyRelease, data.result)
+
+ container.destroy()
+ }
}