summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-09-14 18:26:40 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-11-01 13:06:30 +0000
commit1d5a2e924bfda9cf5eb8118812cb4652b97178b7 (patch)
tree3c7bea1abcba27fbda68985da6c6a4d9e88f5187
parent13811a19d6bc7a63d5827e22b3ae2c006483b227 (diff)
macOS: Compute NSWindow background color without checking styleMask5.12
The check for styleMask == NSWindowStyleMaskBorderless to decide whether to clear the NSWindow background was broken, as NSWindowStyleMaskBorderless has the value 0, but is only supposed to be compared to its companion NSWindowStyleMaskTitled (with value 1). A window can perfectly well be NSWindowStyleMaskBorderless and NSWindowStyleMaskMiniaturizable e.g., so by comparing directly to NSWindowStyleMaskBorderless instead of masking to the first bit first we ended up making miniaturizable windows non-translucent. We now check the Qt::FramelessWindowHint directly, and also whether the window is opaque. Ideally we'd have QWindow flags that could plumb WA_NoSystemBackground from Qt Widgets, as well as a background color property on QWindow to control the system background, but in the meantime we'll have to use the FramelessWindowHint heuristic. The QWidget docs have been updated to reflect this. Task-number: QTBUG-95042 Change-Id: I0d40eecace60883c205ebb8c76cef1092cdf1144 (cherry picked from commit 2f6d572dad031d2757a0f307cba56ae7b01c390a) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/plugins/platforms/cocoa/qnswindow.mm14
-rw-r--r--src/widgets/kernel/qwidget.cpp2
2 files changed, 14 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm
index 1a74fd73f8..8cff444359 100644
--- a/src/plugins/platforms/cocoa/qnswindow.mm
+++ b/src/plugins/platforms/cocoa/qnswindow.mm
@@ -253,8 +253,18 @@ static bool isMouseEvent(NSEvent *ev)
- (NSColor *)backgroundColor
{
- return self.styleMask == NSWindowStyleMaskBorderless ?
- [NSColor clearColor] : [super backgroundColor];
+ // FIXME: Plumb to a WA_NoSystemBackground-like window flag,
+ // or a QWindow::backgroundColor() property. In the meantime
+ // we assume that if you have translucent content, without a
+ // frame then you intend to do all background drawing yourself.
+ const QWindow *window = m_platformWindow ? m_platformWindow->window() : nullptr;
+ if (!self.opaque && window && window->flags().testFlag(Qt::FramelessWindowHint))
+ return [NSColor clearColor];
+
+ // This still allows you to have translucent content with a frame,
+ // where the system background (or color set via NSWindow) will
+ // shine through.
+ return [super backgroundColor];
}
- (void)sendEvent:(NSEvent*)theEvent
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 85fa2ffe39..02a1980e09 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -910,6 +910,8 @@ void QWidget::setAutoFillBackground(bool enabled)
and a compositing window manager.
\li Windows: The widget needs to have the Qt::FramelessWindowHint window flag set
for the translucency to work.
+ \li \macos: The widget needs to have the Qt::FramelessWindowHint window flag set
+ for the translucency to work.
\endlist