From 1741034090fa462c2a7ed07490162dcacfd883b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 17 Feb 2022 17:28:16 +0100 Subject: [PATCH] Ensure QMainWindow has WA_TranslucentBackground when using unified toolbar Otherwise the QWindow will not end up with a surface format with an alpha. This issue had been hiding in the shadows because we hard-code the backing store image format to include an alpha, but was discovered when trying to use RHI to flush the backing store, which does respect the window format. Pick-to: 6.2 6.3 Change-Id: Ie2b28ca605fc7aa1b1ed22885c8f56e76d3a0305 Reviewed-by: Timur Pocheptsov --- src/widgets/widgets/qmainwindow.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index 5aeea88e4e..cadb5a562f 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -1362,8 +1362,15 @@ void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool enabled) Q_D(QMainWindow); d->useUnifiedToolBar = enabled; - createWinId(); + // The unified toolbar is drawn by the macOS style with a transparent background. + // To ensure a suitable surface format is used we need to first create backing + // QWindow so we have something to update the surface format on, and then let + // QWidget know about the translucency, which it will propagate to the surface. + setAttribute(Qt::WA_NativeWindow); + setAttribute(Qt::WA_TranslucentBackground, enabled); + + d->create(); // Create first, before querying the platform window using namespace QNativeInterface::Private; if (auto *platformWindow = dynamic_cast(window()->windowHandle()->handle())) platformWindow->setContentBorderEnabled(enabled);