aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quickwidgets
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2017-02-22 16:16:14 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2017-03-29 15:31:21 +0000
commit0dbc575c1a8359534761167a5f5f1e29abedd51d (patch)
treed1675ab1d58f5540fc1c88a92c1d2046c922b296 /tests/auto/quickwidgets
parentb82d5bb4186952d66ebd4a3f6a21c5d9e8705940 (diff)
Make keyboard events work in QQuickWidget
Right now many cases outside of text input fields are simply broken, e.g. one cannot use a TableView or other controls with the keyboard. Removing the seemingly unnecessary focusObject() solves all problems since this way key events get delivered to the QQuickWidget which in turn forwards to the QQuickWindow. Directly routing into the QQuickWindow's focusObject(), which can be any item in the scene is wrong since it skips a big part of QQuickWindow's event handling logic. Task-number: QTBUG-45757 Change-Id: Ie53b9003d156ab019fa4b9cf461e209990e738f7 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'tests/auto/quickwidgets')
-rw-r--r--tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
index 5e8f762e23..bd051ec990 100644
--- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
+++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
@@ -58,6 +58,7 @@ private slots:
void grabBeforeShow();
void reparentToNewWindow();
void nullEngine();
+ void keyEvents();
};
@@ -337,6 +338,33 @@ void tst_qquickwidget::nullEngine()
QVERIFY(widget.engine());
}
+class KeyHandlingWidget : public QQuickWidget
+{
+public:
+ void keyPressEvent(QKeyEvent *e) override {
+ if (e->key() == Qt::Key_A)
+ ok = true;
+ }
+
+ bool ok = false;
+};
+
+void tst_qquickwidget::keyEvents()
+{
+ // A QQuickWidget should behave like a normal widget when it comes to event handling.
+ // Verify that key events actually reach the widget. (QTBUG-45757)
+ KeyHandlingWidget widget;
+ widget.setSource(testFileUrl("rectangle.qml"));
+ widget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(widget.window(), 5000));
+
+ // Note: send the event to the QWindow, not the QWidget, in order
+ // to simulate the full event processing chain.
+ QTest::keyClick(widget.window()->windowHandle(), Qt::Key_A);
+
+ QTRY_VERIFY(widget.ok);
+}
+
QTEST_MAIN(tst_qquickwidget)
#include "tst_qquickwidget.moc"