mirror of https://github.com/qt/qtbase.git
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:
parent
5bb4817142
commit
78d7192338
|
@ -1054,6 +1054,7 @@ void QMenuBar::mousePressEvent(QMouseEvent *e)
|
||||||
if(QMenu *menu = d->activeMenu) {
|
if(QMenu *menu = d->activeMenu) {
|
||||||
d->activeMenu = 0;
|
d->activeMenu = 0;
|
||||||
menu->hide();
|
menu->hide();
|
||||||
|
d->closePopupMode = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
d->setCurrentAction(action, true);
|
d->setCurrentAction(action, true);
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include <qdesktopwidget.h>
|
#include <qdesktopwidget.h>
|
||||||
#include <qaction.h>
|
#include <qaction.h>
|
||||||
#include <qstyleoption.h>
|
#include <qstyleoption.h>
|
||||||
|
#include <qscreen.h>
|
||||||
|
|
||||||
#include <qobject.h>
|
#include <qobject.h>
|
||||||
|
|
||||||
|
@ -145,6 +146,7 @@ private slots:
|
||||||
void taskQTBUG4965_escapeEaten();
|
void taskQTBUG4965_escapeEaten();
|
||||||
#endif
|
#endif
|
||||||
void taskQTBUG11823_crashwithInvisibleActions();
|
void taskQTBUG11823_crashwithInvisibleActions();
|
||||||
|
void closeOnSecondClick();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void onActivated( QAction*);
|
void onActivated( QAction*);
|
||||||
|
@ -1318,5 +1320,28 @@ void tst_QMenuBar::taskQTBUG11823_crashwithInvisibleActions()
|
||||||
QCOMPARE(menubar.activeAction(), m); //the active action shouldn't have changed
|
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)
|
QTEST_MAIN(tst_QMenuBar)
|
||||||
#include "tst_qmenubar.moc"
|
#include "tst_qmenubar.moc"
|
||||||
|
|
Loading…
Reference in New Issue