summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2019-04-12 12:21:52 +0200
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2019-04-25 12:19:17 +0000
commit913dd26c92f406e3da83ed83701ce47e659bcc48 (patch)
tree227f62bc4c6f2f6fd9b1ec0b8b06315d275cbdba /src
parent9ca81260e9293f6ef9a8e8da08eda7bdbdb90a7d (diff)
QMacStyle - set the proper appearance if needed
Otherwise, AppKit, while rendering 'detached' (not in any view hierarchy) controls and cells will use NSAppearance.currentAppearance, which is not guaranteed to be the same as NSApplication.effectiveAppearance. Task-number: QTBUG-74515 Change-Id: I82dcebf2230932ecfcbf33c422a3b7bd0aed61d7 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index 847b1a6034..2a6f212569 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -447,6 +447,42 @@ static const int toolButtonArrowMargin = 2;
static const qreal focusRingWidth = 3.5;
+// An application can force 'Aqua' theme while the system theme is one of
+// the 'Dark' variants. Since in Qt we sometimes use NSControls and even
+// NSCells directly without attaching them to any view hierarchy, we have
+// to set NSAppearance.currentAppearance to 'Aqua' manually, to make sure
+// the correct rendering path is triggered. Apple recommends us to un-set
+// the current appearance back after we finished with drawing. This is what
+// AppearanceSync is for.
+
+class AppearanceSync {
+public:
+ AppearanceSync()
+ {
+#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14)
+ if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave
+ && !qt_mac_applicationIsInDarkMode()) {
+ auto requiredAppearanceName = NSApplication.sharedApplication.effectiveAppearance.name;
+ if (![NSAppearance.currentAppearance.name isEqualToString:requiredAppearanceName]) {
+ previous = NSAppearance.currentAppearance;
+ NSAppearance.currentAppearance = [NSAppearance appearanceNamed:requiredAppearanceName];
+ }
+ }
+#endif // QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14)
+ }
+
+ ~AppearanceSync()
+ {
+ if (previous)
+ NSAppearance.currentAppearance = previous;
+ }
+
+private:
+ NSAppearance *previous = nil;
+
+ Q_DISABLE_COPY(AppearanceSync)
+};
+
static bool setupScroller(NSScroller *scroller, const QStyleOptionSlider *sb)
{
const qreal length = sb->maximum - sb->minimum + sb->pageStep;
@@ -2918,6 +2954,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
const QWidget *w) const
{
Q_D(const QMacStyle);
+ const AppearanceSync appSync;
QMacCGContext cg(p);
QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr;
d->resolveCurrentNSView(window);
@@ -3443,6 +3480,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
const QWidget *w) const
{
Q_D(const QMacStyle);
+ const AppearanceSync sync;
QMacCGContext cg(p);
QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr;
d->resolveCurrentNSView(window);
@@ -5033,6 +5071,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
const QWidget *widget) const
{
Q_D(const QMacStyle);
+ const AppearanceSync sync;
QMacCGContext cg(p);
QWindow *window = widget && widget->window() ? widget->window()->windowHandle() : nullptr;
d->resolveCurrentNSView(window);