Only scroll QMenu when there is a valid active action

When changing the active action via QMenu::setActiveAction
the menu will scroll to the active action, but we were
scrolling the menu also when the active action was null,
resulting in the menu scrolling back to the top.

We fix this by guarding the call to scrollMenu.

Fixes: QTBUG-92096
Pick-to: 5.15 6.0 6.1
Change-Id: I998f99ddacec32640834d59a907d569fdda458f0
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Zhang Hao 2021-03-24 19:37:04 +08:00 committed by Tor Arne Vestbø
parent edcb5ed697
commit 94e03e506a

View File

@ -2228,7 +2228,7 @@ void QMenu::setActiveAction(QAction *act)
{
Q_D(QMenu);
d->setCurrentAction(act, 0);
if (d->scroll)
if (d->scroll && act)
d->scrollMenu(act, QMenuPrivate::QMenuScroller::ScrollCenter);
}