aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktextedit
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-07-12 14:44:58 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-07-14 05:41:36 +0000
commit8c1aa278e20d2cf3a4b4c5c5410f323a64338469 (patch)
tree9490813dc6e50718cbebff6af0c65d247ec2b2c5 /tests/auto/quick/qquicktextedit
parentce404537816c598891256041556aa3d6fb8ec798 (diff)
TextEdit: ignore all key release events
Input events are accepted by default, and get ignored by the default event handler implementations. By overriding an event handler, the events get accepted, unless ignored explicitly. Since QQuickTextControl does not handle any key release events, it should explicitly ignore all of them, not just Key_Back (ignoring of which was added in 798112b6532a3c66abff630327d29a980a525f25). Fixes: QTBUG-95073 Change-Id: I09105fd8ebef73c03eb2083149643d188a2f1360 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 6ca31ca88a7ee86308e329afd6cd2c90a050d4d9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quick/qquicktextedit')
-rw-r--r--tests/auto/quick/qquicktextedit/data/keyEventPropagation.qml31
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp43
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextedit/data/keyEventPropagation.qml b/tests/auto/quick/qquicktextedit/data/keyEventPropagation.qml
new file mode 100644
index 0000000000..7793827b77
--- /dev/null
+++ b/tests/auto/quick/qquicktextedit/data/keyEventPropagation.qml
@@ -0,0 +1,31 @@
+import QtQuick
+
+FocusScope {
+ Component.onCompleted: edit.forceActiveFocus()
+
+ anchors.fill: parent
+
+ Keys.onPressed: function(event) { keyDown(event.key) }
+ Keys.onReleased: function(event) { keyUp(event.key) }
+ signal keyDown(int key)
+ signal keyUp(int key)
+
+ TextEdit {
+ id: edit
+ anchors.centerIn: parent
+ width: 50
+ height: 50
+ Keys.onPressed: function(event) {
+ event.accepted = event.key == Qt.Key_A || event.key == Qt.Key_Right
+ }
+ Keys.onReleased: function(event) {
+ event.accepted = event.key == Qt.Key_A
+ }
+ Rectangle {
+ anchors.fill: parent
+ anchors.margins: -5
+ color: "transparent"
+ border.width: 1
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index ab35e374c7..73723f857c 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -232,6 +232,8 @@ private slots:
void inFlickableTouch_data();
void inFlickableTouch();
+ void keyEventPropagation();
+
private:
void simulateKeys(QWindow *window, const QList<Key> &keys);
#if QT_CONFIG(shortcut)
@@ -6002,6 +6004,47 @@ void tst_qquicktextedit::transparentSelectionColor()
QVERIFY(color.green() < 10);
}
+void tst_qquicktextedit::keyEventPropagation()
+{
+ QQuickView view;
+ view.setSource(testFileUrl("keyEventPropagation.qml"));
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QObject *root = view.rootObject();
+ QVERIFY(root);
+
+ QSignalSpy downSpy(root, SIGNAL(keyDown(int)));
+ QSignalSpy upSpy(root, SIGNAL(keyUp(int)));
+
+ QQuickTextEdit *textEdit = root->findChild<QQuickTextEdit *>();
+ QVERIFY(textEdit->hasActiveFocus());
+ simulateKey(&view, Qt::Key_Back);
+ QCOMPARE(downSpy.count(), 1);
+ QCOMPARE(upSpy.count(), 1);
+ auto downKey = downSpy.takeFirst();
+ auto upKey = upSpy.takeFirst();
+ QCOMPARE(downKey.at(0).toInt(), Qt::Key_Back);
+ QCOMPARE(upKey.at(0).toInt(), Qt::Key_Back);
+
+ simulateKey(&view, Qt::Key_Shift);
+ QCOMPARE(downSpy.count(), 1);
+ QCOMPARE(upSpy.count(), 1);
+ downKey = downSpy.takeFirst();
+ upKey = upSpy.takeFirst();
+ QCOMPARE(downKey.at(0).toInt(), Qt::Key_Shift);
+ QCOMPARE(upKey.at(0).toInt(), Qt::Key_Shift);
+
+ simulateKey(&view, Qt::Key_A);
+ QCOMPARE(downSpy.count(), 0);
+ QCOMPARE(upSpy.count(), 0);
+
+ simulateKey(&view, Qt::Key_Right);
+ QCOMPARE(downSpy.count(), 0);
+ QCOMPARE(upSpy.count(), 1);
+ upKey = upSpy.takeFirst();
+ QCOMPARE(upKey.at(0).toInt(), Qt::Key_Right);
+}
+
QTEST_MAIN(tst_qquicktextedit)
#include "tst_qquicktextedit.moc"