diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2022-02-17 17:28:16 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-18 17:48:44 +0000 |
commit | e78c413d0f5df58c4b996baae947f96fe8752d55 (patch) | |
tree | fabbdb71e0277099823c9a3ec0360419b4e31d74 | |
parent | 0e7ab00374be050e3795b57e3227f40dd07c1df3 (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.
Change-Id: Ie2b28ca605fc7aa1b1ed22885c8f56e76d3a0305
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 1741034090fa462c2a7ed07490162dcacfd883b0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/widgets/widgets/qmainwindow.cpp | 9 |
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); |