From 468b33d8f86a6d127365518ae2d49211bc7cc7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Tue, 17 May 2022 09:36:54 +0200 Subject: [PATCH] Fix QMenu size on first show QWidget::metric is used to calculate the size of the menu, but it only respects a sceen from a Window handle, so we need to make sure such a thing is created. Task-number: QTBUG-103309 Pick-to: 6.2 6.3 Change-Id: Ie73e362cdcb3b59f46ad51c4901fdbeda7258baa Reviewed-by: Morten Kristensen Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmenu.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 8e62928f41d..adf538b37af 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2315,6 +2315,15 @@ void QMenuPrivate::popup(const QPoint &p, QAction *atAction, PositionFunction po lastContextMenu = contextMenu; } + // Until QWidget::metric accepts the screen set on a widget (without having a window handle) + // we need to make sure we get a window handle. This must be done near here because + // we want the screen to be correctly set and items to be marked dirty. + // (and screen set could 'fail' on oldscreen == newScreen if created before causing the + // itemsDirty not to be set though needed to get the correct size on first show). + if (!windowHandle()) { + createWinId(); + } + #if QT_CONFIG(menubar) // if this menu is part of a chain attached to a QMenuBar, set the // _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type