Open menu on the third click on QMenuBar on X11
authorAlexander Volkov <a.volkov@rusbitech.ru>
Wed, 10 Jun 2015 10:33:09 +0000 (13:33 +0300)
committerAlexander Volkov <a.volkov@rusbitech.ru>
Mon, 17 Aug 2015 09:03:22 +0000 (09:03 +0000)
We don't replay mouse events after closing popups on X11.
This leads to the bug when the menu doesn't show after
clicking three times on the menu bar. It can be fixed by
reverting 78d7192338e2cbba0c9b53c429d35b9437b7e1cd, but
then we need an alternative fix for QTBUG-32807 on Windows.
So don't replay mouse events for the menu bar on all
platforms.

Change-Id: I3db8e24a6de6f35b0a17dffac6a131f1cad42e6d
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
src/widgets/widgets/qmenubar.cpp
tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp

index 1ad99bed9c0200084e104a84b958b30de2f2c680..883fd3a945eb7b3aea715fd6f9f02bb4a5700975 100644 (file)
@@ -1042,8 +1042,8 @@ void QMenuBar::mousePressEvent(QMouseEvent *e)
     if(d->currentAction == action && d->popupState) {
         if(QMenu *menu = d->activeMenu) {
             d->activeMenu = 0;
+            menu->setAttribute(Qt::WA_NoMouseReplay);
             menu->hide();
-            d->closePopupMode = 1;
         }
     } else {
         d->setCurrentAction(action, true);
index f7cc69f83d4f3dd555f0d1b819bd72a022c1f225..31e9c737e2d2febbdefc38299e074447adff2968 100644 (file)
@@ -128,7 +128,7 @@ private slots:
     void taskQTBUG4965_escapeEaten();
 #endif
     void taskQTBUG11823_crashwithInvisibleActions();
-    void closeOnSecondClick();
+    void closeOnSecondClickAndOpenOnThirdClick();
     void cornerWidgets_data();
     void cornerWidgets();
 
@@ -1312,7 +1312,7 @@ void tst_QMenuBar::taskQTBUG11823_crashwithInvisibleActions()
     QCOMPARE(menubar.activeAction(), m); //the active action shouldn't have changed
 }
 
-void tst_QMenuBar::closeOnSecondClick() // QTBUG-32807, menu should close on 2nd click.
+void tst_QMenuBar::closeOnSecondClickAndOpenOnThirdClick() // QTBUG-32807, menu should close on 2nd click.
 {
     QMainWindow mainWindow;
     mainWindow.resize(300, 200);
@@ -1322,17 +1322,20 @@ void tst_QMenuBar::closeOnSecondClick() // QTBUG-32807, menu should close on 2nd
 #endif
     QMenuBar *menuBar = mainWindow.menuBar();
     menuBar->setNativeMenuBar(false);
-    QMenu *fileMenu = menuBar->addMenu(QStringLiteral("closeOnSecondClick"));
+    QMenu *fileMenu = menuBar->addMenu(QStringLiteral("OpenCloseOpen"));
     fileMenu->addAction(QStringLiteral("Quit"));
     mainWindow.show();
     QApplication::setActiveWindow(&mainWindow);
     QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
     const QPoint center = menuBar->actionGeometry(fileMenu->menuAction()).center();
+    const QPoint globalPos = menuBar->mapToGlobal(center);
     QTest::mouseMove(menuBar, center);
     QTest::mouseClick(menuBar, Qt::LeftButton, 0, center);
     QTRY_VERIFY(fileMenu->isVisible());
-    QTest::mouseClick(menuBar, Qt::LeftButton, 0, center);
+    QTest::mouseClick(fileMenu, Qt::LeftButton, 0, fileMenu->mapFromGlobal(globalPos));
     QTRY_VERIFY(!fileMenu->isVisible());
+    QTest::mouseClick(menuBar, Qt::LeftButton, 0, center);
+    QTRY_VERIFY(fileMenu->isVisible());
 }
 
 Q_DECLARE_METATYPE(Qt::Corner)