Close menu on 2nd click on QMenuBar.

Task-number: QTBUG-32807
Change-Id: I0c3c25c6acf92bc30c1bcfc09003209b572ec777
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
This commit is contained in:
Friedemann Kleint 2013-08-27 11:58:34 +02:00 committed by The Qt Project
parent 5bb4817142
commit 78d7192338
2 changed files with 26 additions and 0 deletions

View File

@ -1054,6 +1054,7 @@ void QMenuBar::mousePressEvent(QMouseEvent *e)
if(QMenu *menu = d->activeMenu) {
d->activeMenu = 0;
menu->hide();
d->closePopupMode = 1;
}
} else {
d->setCurrentAction(action, true);

View File

@ -50,6 +50,7 @@
#include <qdesktopwidget.h>
#include <qaction.h>
#include <qstyleoption.h>
#include <qscreen.h>
#include <qobject.h>
@ -145,6 +146,7 @@ private slots:
void taskQTBUG4965_escapeEaten();
#endif
void taskQTBUG11823_crashwithInvisibleActions();
void closeOnSecondClick();
protected slots:
void onActivated( QAction*);
@ -1318,5 +1320,28 @@ 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.
{
QMainWindow mainWindow;
mainWindow.resize(300, 200);
mainWindow.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(150, 100));
#ifndef QT_NO_CURSOR
QCursor::setPos(mainWindow.geometry().topLeft() - QPoint(100, 0));
#endif
QMenuBar *menuBar = mainWindow.menuBar();
menuBar->setNativeMenuBar(false);
QMenu *fileMenu = menuBar->addMenu(QStringLiteral("closeOnSecondClick"));
fileMenu->addAction(QStringLiteral("Quit"));
mainWindow.show();
QApplication::setActiveWindow(&mainWindow);
QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
const QPoint center = menuBar->actionGeometry(fileMenu->menuAction()).center();
QTest::mouseMove(menuBar, center);
QTest::mouseClick(menuBar, Qt::LeftButton, 0, center);
QTRY_VERIFY(fileMenu->isVisible());
QTest::mouseClick(menuBar, Qt::LeftButton, 0, center);
QTRY_VERIFY(!fileMenu->isVisible());
}
QTEST_MAIN(tst_QMenuBar)
#include "tst_qmenubar.moc"