Fix closing a QMenu by pressing Alt.
In QMenuPrivate::hideMenu(), delay clearing of 'causedPopup.widget' to after the QMenu::close() call, so that it is still accessible in QMenu::hideEvent() which calls QMenuBarPrivate::setCurrentAction(0) if the caused widget is a QMenuBar. Task-number: QTBUG-47377 Task-number: QTBUG-49592 Change-Id: Idbda48e918dae799afea84068a60d7383d7b4971 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
884e3bdd5d
commit
4eea99788b
@ -502,8 +502,8 @@ void QMenuPrivate::hideMenu(QMenu *menu)
|
|||||||
if (activeMenu == menu)
|
if (activeMenu == menu)
|
||||||
activeMenu = 0;
|
activeMenu = 0;
|
||||||
menu->d_func()->causedPopup.action = 0;
|
menu->d_func()->causedPopup.action = 0;
|
||||||
menu->d_func()->causedPopup.widget = 0;
|
|
||||||
menu->close();
|
menu->close();
|
||||||
|
menu->d_func()->causedPopup.widget = 0;
|
||||||
if (previousMouseMenu.data() == menu)
|
if (previousMouseMenu.data() == menu)
|
||||||
handleEnterLeaveEvents(&previousMouseMenu, Q_NULLPTR);
|
handleEnterLeaveEvents(&previousMouseMenu, Q_NULLPTR);
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,7 @@ private slots:
|
|||||||
// void check_mouse2();
|
// void check_mouse2();
|
||||||
|
|
||||||
void check_altPress();
|
void check_altPress();
|
||||||
|
void check_altClosePress();
|
||||||
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
|
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
|
||||||
void check_shortcutPress();
|
void check_shortcutPress();
|
||||||
void check_menuPosition();
|
void check_menuPosition();
|
||||||
@ -978,6 +979,35 @@ void tst_QMenuBar::check_altPress()
|
|||||||
QTRY_VERIFY( ::qobject_cast<QMenuBar *>(qApp->focusWidget()) );
|
QTRY_VERIFY( ::qobject_cast<QMenuBar *>(qApp->focusWidget()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QTBUG-47377: Pressing 'Alt' after opening a menu by pressing 'Alt+Accelerator'
|
||||||
|
// should close it and QMenuBar::activeAction() should be 0.
|
||||||
|
void tst_QMenuBar::check_altClosePress()
|
||||||
|
{
|
||||||
|
const QStyle *style = QApplication::style();
|
||||||
|
if (!style->styleHint(QStyle::SH_MenuBar_AltKeyNavigation) ) {
|
||||||
|
QSKIP(("This test is not supposed to work in the " + style->objectName().toLatin1()
|
||||||
|
+ " style. Skipping.").constData());
|
||||||
|
}
|
||||||
|
|
||||||
|
QMainWindow w;
|
||||||
|
w.setWindowTitle(QTest::currentTestFunction());
|
||||||
|
QMenu *menuFile = w.menuBar()->addMenu(tr("&File"));
|
||||||
|
menuFile->addAction("Quit");
|
||||||
|
QMenu *menuEdit = w.menuBar()->addMenu(tr("&Edit"));
|
||||||
|
menuEdit->addAction("Copy");
|
||||||
|
|
||||||
|
w.show();
|
||||||
|
w.move(QGuiApplication::primaryScreen()->availableGeometry().center());
|
||||||
|
QApplication::setActiveWindow(&w);
|
||||||
|
QVERIFY(QTest::qWaitForWindowActive(&w));
|
||||||
|
|
||||||
|
QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier);
|
||||||
|
QTRY_VERIFY(menuFile->isVisible());
|
||||||
|
QTest::keyClick(menuFile, Qt::Key_Alt, Qt::AltModifier);
|
||||||
|
QTRY_VERIFY(!menuFile->isVisible());
|
||||||
|
QTRY_VERIFY(!w.menuBar()->activeAction());
|
||||||
|
}
|
||||||
|
|
||||||
// Qt/Mac,WinCE does not use the native popups/menubar
|
// Qt/Mac,WinCE does not use the native popups/menubar
|
||||||
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
|
#if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE)
|
||||||
void tst_QMenuBar::check_shortcutPress()
|
void tst_QMenuBar::check_shortcutPress()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user