aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickmenu.cpp2
-rw-r--r--tests/auto/menu/data/mnemonics.qml87
-rw-r--r--tests/auto/menu/tst_menu.cpp49
3 files changed, 138 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp
index 14449ad5..8ac7e303 100644
--- a/src/quicktemplates2/qquickmenu.cpp
+++ b/src/quicktemplates2/qquickmenu.cpp
@@ -260,6 +260,8 @@ QQuickItem *QQuickMenuPrivate::beginCreateItem()
if (!item)
delete object;
+ QQml_setParent_noEvent(item, q);
+
return item;
}
diff --git a/tests/auto/menu/data/mnemonics.qml b/tests/auto/menu/data/mnemonics.qml
new file mode 100644
index 00000000..de4cd215
--- /dev/null
+++ b/tests/auto/menu/data/mnemonics.qml
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Controls 2.3
+
+ApplicationWindow {
+ width: 400
+ height: 400
+
+ property alias menu: menu
+ property alias action: action
+ property alias menuItem: menuItem
+ property alias subMenu: subMenu
+ property alias subMenuItem: subMenuItem
+
+ Menu {
+ id: menu
+
+ Action {
+ id: action
+ text: "&Action"
+ }
+
+ MenuItem {
+ id: menuItem
+ text: "Menu &Item"
+ }
+
+ Menu {
+ id: subMenu
+ title: "Sub &Menu"
+
+ MenuItem {
+ id: subMenuItem
+ text: "&Sub Menu Item"
+ }
+ }
+ }
+}
diff --git a/tests/auto/menu/tst_menu.cpp b/tests/auto/menu/tst_menu.cpp
index 981e95cf..c9105f9e 100644
--- a/tests/auto/menu/tst_menu.cpp
+++ b/tests/auto/menu/tst_menu.cpp
@@ -67,6 +67,7 @@ private slots:
void mouse();
void pressAndHold();
void contextMenuKeyboard();
+ void mnemonics();
void menuButton();
void addItem();
void menuSeparator();
@@ -351,6 +352,54 @@ void tst_menu::contextMenuKeyboard()
QVERIFY(!menu->isVisible());
}
+void tst_menu::mnemonics()
+{
+#ifdef Q_OS_MACOS
+ QSKIP("Mnemonics are not used on macOS");
+#endif
+
+ QQuickApplicationHelper helper(this, QLatin1String("mnemonics.qml"));
+
+ QQuickWindow *window = helper.window;
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu *>();
+ QQuickAction *action = window->property("action").value<QQuickAction *>();
+ QQuickMenuItem *menuItem = window->property("menuItem").value<QQuickMenuItem *>();
+ QQuickMenu *subMenu = window->property("subMenu").value<QQuickMenu *>();
+ QQuickMenuItem *subMenuItem = window->property("subMenuItem").value<QQuickMenuItem *>();
+ QVERIFY(menu && action && menuItem && subMenu && subMenuItem);
+
+ menu->open();
+ QTRY_VERIFY(menu->isOpened());
+
+ QSignalSpy actionSpy(action, &QQuickAction::triggered);
+ QVERIFY(actionSpy.isValid());
+ QTest::keyClick(window, Qt::Key_A, Qt::AltModifier); // "&Action"
+ QCOMPARE(actionSpy.count(), 1);
+
+ menu->open();
+ QTRY_VERIFY(menu->isOpened());
+
+ QSignalSpy menuItemSpy(menuItem, &QQuickMenuItem::triggered);
+ QVERIFY(menuItemSpy.isValid());
+ QTest::keyClick(window, Qt::Key_I, Qt::AltModifier); // "Menu &Item"
+ QCOMPARE(menuItemSpy.count(), 1);
+
+ menu->open();
+ QTRY_VERIFY(menu->isOpened());
+
+ QTest::keyClick(window, Qt::Key_M, Qt::AltModifier); // "Sub &Menu"
+ QTRY_VERIFY(subMenu->isOpened());
+
+ QSignalSpy subMenuItemSpy(subMenuItem, &QQuickMenuItem::triggered);
+ QVERIFY(subMenuItemSpy.isValid());
+ QTest::keyClick(window, Qt::Key_S, Qt::AltModifier); // "&Sub Menu Item"
+ QCOMPARE(subMenuItemSpy.count(), 1);
+}
+
void tst_menu::menuButton()
{
if (QGuiApplication::styleHints()->tabFocusBehavior() != Qt::TabFocusAllControls)