From ad5565b6438cb239ad36722605a31b1006cd6478 Mon Sep 17 00:00:00 2001 From: Oleg Yadrov Date: Thu, 12 Jan 2017 10:03:10 -0800 Subject: Wide QMenu: fix size and position MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fixes 2 issues related to wide menus: 1) Menu took on full screen height when menu width was larger than screen width; 2) On a multi-display system wide menu might appear on wrong monitor (not the one where show event was triggered). The idea is we limit parent menu and all its submenus within the screen where it was opened. Note that this patch fixes only geometry-related issues and there are also some style flaws which need to be addressed (for example, currently the text does not elide if it doesn’t fit to the menu’s width). Task-number: QTBUG-56917 Change-Id: I7e9ff4a48bf03060d76e34d33a13ad6cc890c133 Reviewed-by: Gabriel de Dietrich --- tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 3218b8ac68..4e82099706 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -110,6 +111,8 @@ private slots: void QTBUG_37933_ampersands_data(); void QTBUG_37933_ampersands(); #endif + void QTBUG_56917_wideMenuSize(); + void QTBUG_56917_wideMenuScreenNumber(); protected slots: void onActivated(QAction*); void onHighlighted(QAction*); @@ -1311,5 +1314,39 @@ void tst_QMenu::QTBUG_37933_ampersands() } #endif +void tst_QMenu::QTBUG_56917_wideMenuSize() +{ + // menu shouldn't to take on full screen height when menu width is larger than screen width + QMenu menu; + QString longString; + longString.fill(QLatin1Char('Q'), 3000); + menu.addAction(longString); + QSize menuSizeHint = menu.sizeHint(); + menu.popup(QPoint()); + QTest::qWait(100); + QVERIFY(QTest::qWaitForWindowExposed(&menu)); + QVERIFY(menu.isVisible()); + QVERIFY(menu.height() <= menuSizeHint.height()); +} + +void tst_QMenu::QTBUG_56917_wideMenuScreenNumber() +{ + if (QApplication::styleHints()->showIsFullScreen()) + QSKIP("The platform defaults to windows being fullscreen."); + // menu must appear on the same screen where show action is triggered + QString longString; + longString.fill(QLatin1Char('Q'), 3000); + + for (int i = 0; i < QApplication::desktop()->screenCount(); i++) { + QMenu menu; + menu.addAction(longString); + menu.popup(QApplication::desktop()->screen(i)->geometry().center()); + QTest::qWait(100); + QVERIFY(QTest::qWaitForWindowExposed(&menu)); + QVERIFY(menu.isVisible()); + QCOMPARE(QApplication::desktop()->screenNumber(&menu), i); + } +} + QTEST_MAIN(tst_QMenu) #include "tst_qmenu.moc" -- cgit v1.2.3