summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2012-11-23 17:26:25 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-26 11:00:07 +0100
commiteefec0e0be6b589ff1db8ab44a7f6d3aa2b6ec60 (patch)
treed9b3cd7f411d48a35e774c9587a40d2284ca1705
parent9a33cdd8f041f2bca621ed5c08e82885fb32aeec (diff)
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>
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp2
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp22
2 files changed, 24 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index b700d33f52..78d6a293b9 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -414,6 +414,8 @@ void QWidgetWindow::handleKeyEvent(QKeyEvent *event)
receiver = popupFocusWidget ? popupFocusWidget : popup;
}
if (!receiver)
+ receiver = QWidget::keyboardGrabber();
+ if (!receiver)
receiver = focusObject();
QGuiApplication::sendSpontaneousEvent(receiver, event);
}
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 2a5e59f825..432950b8ec 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -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)