From 8387d87bdcf7dfb359515f44b17f523791bc8edb Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 2 Mar 2017 08:55:35 +0100 Subject: QDialogButtonGroup: Fix removal of deleted buttons As the destroyed() signal is emitted from ~QObject, it is not allowed to use static_cast to a QAbstractButton on that pointer anymore. And the qobject_cast will also fail which will keep a dangling pointer in the hash. Change-Id: If0d22fcc30cde87e771e70914c3afb04ea207289 Reviewed-by: Marc Mutz --- .../widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/auto/widgets/widgets') diff --git a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp index a35ea8eb6e..f127fd98f7 100644 --- a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp +++ b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp @@ -97,6 +97,8 @@ private slots: void testDefaultButton(); void task191642_default(); + void testDeletedStandardButton(); + private: qint64 timeStamp; qint64 buttonClicked1TimeStamp; @@ -843,5 +845,22 @@ void tst_QDialogButtonBox::task191642_default() QCOMPARE(clicked.count(), 1); } +void tst_QDialogButtonBox::testDeletedStandardButton() +{ + QDialogButtonBox buttonBox; + delete buttonBox.addButton(QDialogButtonBox::Ok); + QPointer buttonC = buttonBox.addButton(QDialogButtonBox::Cancel); + delete buttonBox.addButton(QDialogButtonBox::Cancel); + QPointer buttonA = buttonBox.addButton(QDialogButtonBox::Apply); + delete buttonBox.addButton(QDialogButtonBox::Help); + // A few button have been deleted, they should automatically be removed + QCOMPARE(buttonBox.standardButtons(), QDialogButtonBox::Apply | QDialogButtonBox::Cancel); + + buttonBox.setStandardButtons(QDialogButtonBox::Reset | QDialogButtonBox::Cancel); + // setStanderdButton should delete previous buttons + QVERIFY(!buttonA); + QVERIFY(!buttonC); +} + QTEST_MAIN(tst_QDialogButtonBox) #include "tst_qdialogbuttonbox.moc" -- cgit v1.2.3 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/auto/widgets/widgets') 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 From f2e103296f9077a747e0dd43504e3e7630f56605 Mon Sep 17 00:00:00 2001 From: Oleg Yadrov Date: Fri, 13 Jan 2017 10:33:49 -0800 Subject: QMenu: make wide submenu appear on the same screen with its parent menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a multi-display system wide submenu might either appear on wrong screen or not appear at all (depending on the specific display configuration). Task-number: QTBUG-56917 Change-Id: I40013b0bee340a01ae1c08a5e074afa63da4dbfd Reviewed-by: Gabriel de Dietrich Reviewed-by: Błażej Szczygieł --- tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/auto/widgets/widgets') diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 4e82099706..b037cc2141 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -113,6 +113,7 @@ private slots: #endif void QTBUG_56917_wideMenuSize(); void QTBUG_56917_wideMenuScreenNumber(); + void QTBUG_56917_wideSubmenuScreenNumber(); protected slots: void onActivated(QAction*); void onHighlighted(QAction*); @@ -1348,5 +1349,29 @@ void tst_QMenu::QTBUG_56917_wideMenuScreenNumber() } } +void tst_QMenu::QTBUG_56917_wideSubmenuScreenNumber() +{ + if (QApplication::styleHints()->showIsFullScreen()) + QSKIP("The platform defaults to windows being fullscreen."); + // submenu must appear on the same screen where its parent menu is shown + QString longString; + longString.fill(QLatin1Char('Q'), 3000); + + for (int i = 0; i < QApplication::desktop()->screenCount(); i++) { + QMenu menu; + QMenu submenu("Submenu"); + submenu.addAction(longString); + QAction *action = menu.addMenu(&submenu); + menu.popup(QApplication::desktop()->screen(i)->geometry().center()); + QVERIFY(QTest::qWaitForWindowExposed(&menu)); + QVERIFY(menu.isVisible()); + QTest::mouseClick(&menu, Qt::LeftButton, 0, menu.actionGeometry(action).center()); + QTest::qWait(100); + QVERIFY(QTest::qWaitForWindowExposed(&submenu)); + QVERIFY(submenu.isVisible()); + QCOMPARE(QApplication::desktop()->screenNumber(&submenu), i); + } +} + QTEST_MAIN(tst_QMenu) #include "tst_qmenu.moc" -- cgit v1.2.3