aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickshortcutcontext.cpp2
-rw-r--r--tests/auto/controls/data/tst_popup.qml38
2 files changed, 38 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickshortcutcontext.cpp b/src/quicktemplates2/qquickshortcutcontext.cpp
index e94de722..4e4b46fa 100644
--- a/src/quicktemplates2/qquickshortcutcontext.cpp
+++ b/src/quicktemplates2/qquickshortcutcontext.cpp
@@ -77,7 +77,7 @@ bool QQuickShortcutContext::matcher(QObject *obj, Qt::ShortcutContext context)
case Qt::WindowShortcut:
while (obj && !obj->isWindowType()) {
item = qobject_cast<QQuickItem *>(obj);
- if (item) {
+ if (item && item->window()) {
obj = item->window();
break;
} else if (QQuickPopup *popup = qobject_cast<QQuickPopup *>(obj)) {
diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml
index 3f9f5e48..a6c24cb7 100644
--- a/tests/auto/controls/data/tst_popup.qml
+++ b/tests/auto/controls/data/tst_popup.qml
@@ -48,7 +48,7 @@
**
****************************************************************************/
-import QtQuick 2.4
+import QtQuick 2.11
import QtTest 1.0
import QtQuick.Controls 2.3
import QtQuick.Templates 2.3 as T
@@ -1269,4 +1269,40 @@ TestCase {
compare(control.background.width, 200 + (control.background.leftInset || 0) + (control.background.rightInset || 0))
compare(control.background.height, 100 + (control.background.topInset || 0) + (control.background.bottomInset || 0))
}
+
+
+ Component {
+ id: shortcutWindowComponent
+ ApplicationWindow {
+ id: window
+ width: 360
+ height: 360
+ visible: true
+
+ property alias popup: popup
+
+ Popup {
+ id: popup
+
+ Shortcut {
+ sequence: "Tab"
+ onActivated: popup.visible = !popup.visible
+ }
+ }
+ }
+ }
+
+ function test_shortcut() {
+ // Tests that a Shortcut with Qt.WindowShortcut context
+ // that is declared within a Popup is activated.
+ var window = createTemporaryObject(shortcutWindowComponent, testCase)
+ var control = window.popup
+
+ waitForRendering(window.contentItem)
+ keyClick(Qt.Key_Tab)
+ tryCompare(control, "visible", true)
+
+ keyClick(Qt.Key_Tab)
+ tryCompare(control, "visible", false)
+ }
}