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 <jason.mcdonald@nokia.com>
This commit is contained in:
parent
79fb588030
commit
5761d8546f
@ -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
|
||||
|
@ -1249,10 +1249,12 @@ void tst_QMenuBar::taskQTBUG4965_escapeEaten()
|
||||
menubar.setActiveAction(first);
|
||||
QTRY_VERIFY(menu.isVisible());
|
||||
QCOMPARE(menubar.activeAction(), first);
|
||||
QTest::qWaitForWindowShown(&menu);
|
||||
QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Escape);
|
||||
QVERIFY(!menu.isVisible());
|
||||
QTRY_VERIFY(menubar.hasFocus());
|
||||
QCOMPARE(menubar.activeAction(), first);
|
||||
QTest::qWait(200);
|
||||
QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Escape);
|
||||
QVERIFY(!menubar.activeAction());
|
||||
QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Escape); //now the action should be triggered
|
||||
|
Loading…
Reference in New Issue
Block a user