From 5761d8546f3ff3802cae85ed5224c2bdd9524452 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 21 Oct 2011 11:01:21 +0200 Subject: Correctly handle null windows or widgets in keyClick() Allow passing of null windows or widgets to keyClick(). In that case route the event through the normal Qt event processing. This allows e.g. shortcuts to catch the key event. Change-Id: Ic9455ea9be5164918b1c0bccbd58dd32eae74ff1 Reviewed-by: Jason McDonald --- src/testlib/qtestkeyboard.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/testlib/qtestkeyboard.h') diff --git a/src/testlib/qtestkeyboard.h b/src/testlib/qtestkeyboard.h index e2c02ac496..deb572b8fd 100644 --- a/src/testlib/qtestkeyboard.h +++ b/src/testlib/qtestkeyboard.h @@ -85,8 +85,13 @@ namespace QTest QString text, Qt::KeyboardModifiers modifier, int delay=-1) { QTEST_ASSERT(qApp); + + if (!window) + window = QGuiApplication::activeWindow(); + QTEST_ASSERT(window); + if (action == Click) { sendKeyEvent(Press, window, code, text, modifier, delay); sendKeyEvent(Release, window, code, text, modifier, delay); @@ -183,6 +188,12 @@ namespace QTest if (!widget) widget = QWidget::keyboardGrabber(); if (!widget) { + QWindow *window = QGuiApplication::focusWindow(); + if (window) { + sendKeyEvent(action, window, code, text, modifier, delay); + return; + } + if (QWidget *apw = QApplication::activePopupWidget()) widget = apw->focusWidget() ? apw->focusWidget() : apw; else -- cgit v1.2.3