diff options
Diffstat (limited to 'src/qmltest')
-rw-r--r-- | src/qmltest/quicktestevent.cpp | 19 | ||||
-rw-r--r-- | src/qmltest/quicktestevent_p.h | 1 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/qmltest/quicktestevent.cpp b/src/qmltest/quicktestevent.cpp index 237bbe76e9..cfa80c4f19 100644 --- a/src/qmltest/quicktestevent.cpp +++ b/src/qmltest/quicktestevent.cpp @@ -50,7 +50,7 @@ QuickTestEvent::~QuickTestEvent() bool QuickTestEvent::keyPress(int key, int modifiers, int delay) { - QWindow *window = eventWindow(); + QWindow *window = activeWindow(); if (!window) return false; QTest::keyPress(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay); @@ -59,7 +59,7 @@ bool QuickTestEvent::keyPress(int key, int modifiers, int delay) bool QuickTestEvent::keyRelease(int key, int modifiers, int delay) { - QWindow *window = eventWindow(); + QWindow *window = activeWindow(); if (!window) return false; QTest::keyRelease(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay); @@ -68,7 +68,7 @@ bool QuickTestEvent::keyRelease(int key, int modifiers, int delay) bool QuickTestEvent::keyClick(int key, int modifiers, int delay) { - QWindow *window = eventWindow(); + QWindow *window = activeWindow(); if (!window) return false; QTest::keyClick(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay); @@ -78,7 +78,7 @@ bool QuickTestEvent::keyClick(int key, int modifiers, int delay) bool QuickTestEvent::keyPressChar(const QString &character, int modifiers, int delay) { QTEST_ASSERT(character.length() == 1); - QWindow *window = eventWindow(); + QWindow *window = activeWindow(); if (!window) return false; QTest::keyPress(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay); @@ -88,7 +88,7 @@ bool QuickTestEvent::keyPressChar(const QString &character, int modifiers, int d bool QuickTestEvent::keyReleaseChar(const QString &character, int modifiers, int delay) { QTEST_ASSERT(character.length() == 1); - QWindow *window = eventWindow(); + QWindow *window = activeWindow(); if (!window) return false; QTest::keyRelease(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay); @@ -98,7 +98,7 @@ bool QuickTestEvent::keyReleaseChar(const QString &character, int modifiers, int bool QuickTestEvent::keyClickChar(const QString &character, int modifiers, int delay) { QTEST_ASSERT(character.length() == 1); - QWindow *window = eventWindow(); + QWindow *window = activeWindow(); if (!window) return false; QTest::keyClick(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay); @@ -316,4 +316,11 @@ QWindow *QuickTestEvent::eventWindow(QObject *item) return 0; } +QWindow *QuickTestEvent::activeWindow() +{ + if (QWindow *window = QGuiApplication::focusWindow()) + return window; + return eventWindow(); +} + QT_END_NAMESPACE diff --git a/src/qmltest/quicktestevent_p.h b/src/qmltest/quicktestevent_p.h index e11674f66a..338464c6b3 100644 --- a/src/qmltest/quicktestevent_p.h +++ b/src/qmltest/quicktestevent_p.h @@ -74,6 +74,7 @@ public Q_SLOTS: private: QWindow *eventWindow(QObject *item = 0); + QWindow *activeWindow(); }; QT_END_NAMESPACE |