summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qmainwindow.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-02-17 17:28:16 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-02-18 15:26:32 +0100
commit1741034090fa462c2a7ed07490162dcacfd883b0 (patch)
tree5d2542a8f14139c5899122eec87634bc64e71c81 /src/widgets/widgets/qmainwindow.cpp
parent8875b5a9a3c53bc13f044238c704d230f5a0a13a (diff)
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 <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/widgets/widgets/qmainwindow.cpp')
-rw-r--r--src/widgets/widgets/qmainwindow.cpp9
1 files changed, 8 insertions, 1 deletions
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<QCocoaWindow*>(window()->windowHandle()->handle()))
platformWindow->setContentBorderEnabled(enabled);