From 5a9fbae0ba12622e12287aa1c89f4f3d58379ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 10 Mar 2023 14:30:43 +0100 Subject: [PATCH] QMenuBar: Mark items as dirty when switching away from native menu bar QMenuBarPrivate::updateGeometries() returns early if the native menu bar is in use, skipping the call to calcActionRects, so the action rects are not in sync with the actions in this mode. When switching to non-native menu bars, we would then crash in QMenuBar::minimumSizeHint() because we're iterating the action rects assuming the match the actions. To fix this we need to ensure the action rects are computed by our call to updateGeometries() in setNativeMenuBar(), which we can do by explicitly marking the items as dirty. Note that it's currently not possible to switch back to the native menu bar, as the native menu bar is populated in QMenuBar::actionEvent via QEvent::ActionAdded, and we're not doing anything to re-add these actions once we've recreated the native menu bar. Fixes: QTBUG-102107 Pick-to: 6.5 6.4 6.2 Change-Id: I7cf2b25539da633727693f5894ea22ea0d0d9aa5 Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmenubar.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 18e8807738a..a53bc975161 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1772,6 +1772,7 @@ void QMenuBar::setNativeMenuBar(bool nativeMenuBar) if (!nativeMenuBar) { delete d->platformMenuBar; d->platformMenuBar = nullptr; + d->itemsDirty = true; } else { if (!d->platformMenuBar) d->platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar();