From 2a3f226e325f3ff8456273444a281349cbbd680f Mon Sep 17 00:00:00 2001 From: Yulong Bai Date: Wed, 27 Dec 2017 15:40:16 +0100 Subject: QMenuBar::mouseReleaseEvent: fix triggering hidden actions While menubar actions are hidden, as menubar was too narrow to contain them, by clicking the blank area, where the action was supposed to place, can still trigger the action. Task-number: QTBUG-65488 Change-Id: I6b137e0717f634ebd3371dbcc2c1ce2089688374 Reviewed-by: Richard Moe Gustavsen --- .../auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp') diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 52726c64ac..ab82268578 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -136,7 +136,7 @@ private slots: void task223138_triggered(); void task256322_highlight(); void menubarSizeHint(); -#ifndef Q_OS_MAC +#ifndef Q_OS_MACOS void taskQTBUG4965_escapeEaten(); #endif void taskQTBUG11823_crashwithInvisibleActions(); @@ -153,7 +153,7 @@ private slots: void QTBUG_58344_invalidIcon(); void platformMenu(); void addActionQt5connect(); - + void QTBUG_65488_hiddenActionTriggered(); protected slots: void onSimpleActivated( QAction*); void onComplexActionTriggered(); @@ -1377,7 +1377,7 @@ void tst_QMenuBar::menubarSizeHint() } // On Mac, do not test the menubar with escape key -#ifndef Q_OS_MAC +#ifndef Q_OS_MACOS void tst_QMenuBar::taskQTBUG4965_escapeEaten() { QMenuBar menubar; @@ -1577,6 +1577,25 @@ void tst_QMenuBar::taskQTBUG53205_crashReparentNested() testMenus.actions[0]->trigger(); } +void tst_QMenuBar::QTBUG_65488_hiddenActionTriggered() +{ + QMainWindow win; + win.menuBar()->setNativeMenuBar(false); + QAction *act1 = win.menuBar()->addAction("A very long named action that make menuBar item wide enough"); + QSignalSpy spy(win.menuBar(), &QMenuBar::triggered); + + QRect actRect = win.menuBar()->actionGeometry(act1); + // resize to action's size to make Action1 hidden + win.resize(actRect.width() - 10, win.size().height()); + win.show(); + QApplication::setActiveWindow(&win); + QVERIFY(QTest::qWaitForWindowExposed(&win)); + // click center of the blank area on the menubar where Action1 resided + QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, win.menuBar()->geometry().center()); + QCoreApplication::sendPostedEvents(); // make sure all queued events also dispatched + QCOMPARE(spy.count(), 0); +} + // QTBUG-56526 void tst_QMenuBar::platformMenu() { -- cgit v1.2.3