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 <richard.gustavsen@qt.io>
This commit is contained in:
parent
4ca0d76454
commit
2a3f226e32
@ -1080,6 +1080,10 @@ void QMenuBar::mouseReleaseEvent(QMouseEvent *e)
|
||||
|
||||
d->mouseDown = false;
|
||||
QAction *action = d->actionAt(e->pos());
|
||||
|
||||
// do noting if the action is hidden
|
||||
if (!d->isVisible(action))
|
||||
return;
|
||||
if((d->closePopupMode && action == d->currentAction) || !action || !action->menu()) {
|
||||
//we set the current action before activating
|
||||
//so that we let the leave event set the current back to 0
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user