summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2021-11-25 19:58:42 +0100
committerLiang Qi <liang.qi@qt.io>2021-12-08 13:45:36 +0100
commit493a85a9e468874471057910a61e7c54a45eee83 (patch)
tree9e5c4a10bbc8c7da1bf2e12a172ef4eb6ec5a534 /tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
parent9c05fdac81d5fe0d3007ba55cfddf4eb99183153 (diff)
Widgets: setTransientParent() when a QMenu is a window
On some platforms, such as X11 and Wayland with some compositors, QMenu could be a popup window, which should be set a transient parent to get relative position, which is requested by Wayland. Added transientParentWindow() for QMenuPrivate like QDialogPrivate. Fixes: QTBUG-68636 Pick-to: 6.2 Change-Id: I6d8880cb008ecf61a4c005898b38e3953379a13d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp')
-rw-r--r--tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
index 4b46c05568..31ecd024c0 100644
--- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
+++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
@@ -118,6 +118,7 @@ private slots:
void QTBUG_89082_actionTipsHide();
void QTBUG8122_widgetActionCrashOnClose();
void widgetActionTriggerClosesMenu();
+ void transientParent();
void QTBUG_10735_crashWithDialog();
#ifdef Q_OS_MAC
@@ -1588,6 +1589,54 @@ void tst_QMenu::widgetActionTriggerClosesMenu()
QCOMPARE(actionTriggered, &widgetAction);
}
+void tst_QMenu::transientParent()
+{
+ QMainWindow window;
+ window.resize(480, 320);
+ window.menuBar()->setNativeMenuBar(false);
+ centerOnScreen(&window);
+
+ QMenu *fileMenu = new QMenu("&File");
+ QAction *exitAct = new QAction("Exit");
+ fileMenu->addAction(exitAct);
+
+ QMenu *editMenu = new QMenu("&Edit");
+ QAction *undoAct = new QAction("Undo");
+ editMenu->addAction(undoAct);
+
+ QMenuBar *menuBar = new QMenuBar;
+ menuBar->addMenu(fileMenu);
+ menuBar->addMenu(editMenu);
+ window.setMenuBar(menuBar);
+
+ // On Mac, we need to create native key events to test menu
+ // action activation, so skip this part of the test.
+#if QT_CONFIG(shortcut) && !defined(Q_OS_DARWIN)
+ window.show();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+ QWindow *topLevel = window.windowHandle();
+ QVERIFY(topLevel);
+
+ QApplication::setActiveWindow(&window);
+ window.setFocus();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+ QVERIFY(window.hasFocus());
+
+ QTest::keyPress(&window, Qt::Key_F, Qt::AltModifier);
+ QTRY_VERIFY(QTest::qWaitForWindowExposed(fileMenu));
+ if (fileMenu->isWindow() && fileMenu->window() && fileMenu->window()->windowHandle())
+ QVERIFY(fileMenu->window()->windowHandle()->transientParent());
+ QTest::keyRelease(fileMenu, Qt::Key_F, Qt::AltModifier);
+
+ QTest::keyPress(fileMenu, Qt::Key_E, Qt::AltModifier);
+ QTRY_VERIFY(QTest::qWaitForWindowExposed(editMenu));
+ if (editMenu->isWindow() && editMenu->window() && editMenu->window()->windowHandle())
+ QVERIFY(editMenu->window()->windowHandle()->transientParent());
+ QTest::keyRelease(editMenu, Qt::Key_E, Qt::AltModifier);
+#endif // QT_CONFIG(shortcut) && !Q_OS_DARWIN
+
+}
+
class MyMenu : public QMenu
{
Q_OBJECT