Fix keyboard grab in QWidgetWindow.

Task-number: QTBUG-28070
Change-Id: I6f55a2dd906ee896071137a5d47fb97c9a571b5f
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
bb10
Friedemann Kleint 2012-11-23 17:26:25 +01:00 committed by The Qt Project
parent 9a33cdd8f0
commit eefec0e0be
2 changed files with 24 additions and 0 deletions

View File

@ -413,6 +413,8 @@ void QWidgetWindow::handleKeyEvent(QKeyEvent *event)
QWidget *popupFocusWidget = popup->focusWidget();
receiver = popupFocusWidget ? popupFocusWidget : popup;
}
if (!receiver)
receiver = QWidget::keyboardGrabber();
if (!receiver)
receiver = focusObject();
QGuiApplication::sendSpontaneousEvent(receiver, event);

View File

@ -392,6 +392,7 @@ private slots:
void nativeChildFocus();
void grab();
void grabMouse();
void grabKeyboard();
void touchEventSynthesizedMouseEvent();
@ -9412,6 +9413,27 @@ void tst_QWidget::grabMouse()
QCOMPARE(log, expectedLog);
}
void tst_QWidget::grabKeyboard()
{
QWidget w;
w.setObjectName(QLatin1String("tst_qwidget_grabKeyboard"));
w.setWindowTitle(w.objectName());
QLayout *layout = new QVBoxLayout(&w);
QLineEdit *grabber = new QLineEdit(&w);
layout->addWidget(grabber);
QLineEdit *nonGrabber = new QLineEdit(&w);
layout->addWidget(nonGrabber);
w.show();
qApp->setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
nonGrabber->setFocus();
grabber->grabKeyboard();
QTest::keyClick(w.windowHandle(), Qt::Key_A);
grabber->releaseKeyboard();
QCOMPARE(grabber->text().toLower(), QStringLiteral("a"));
QVERIFY(nonGrabber->text().isEmpty());
}
class TouchMouseWidget : public QWidget {
public:
explicit TouchMouseWidget(QWidget *parent = 0)