diff options
author | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2019-05-13 14:17:35 +0200 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2019-05-15 03:38:11 +0000 |
commit | 95e136380262fd159c305f7d51824126aeaa757e (patch) | |
tree | 011a3d7d5484e4f4bc2be079cb4a2fec32f62662 /src/plugins/styles | |
parent | e9e16c7464364fd15f69e3f37a9ed3edb15b633b (diff) |
QMacStyle - clear cached controls when changing themes
Having Aqua-themed controls in AquaDark theme looks interesting but not
very native. Clear cached Cocoa controls on theme change notification.
Change-Id: I884bf4434211be670aecc317935eb00b3fb6013c
Fixes: QTBUG-73652
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/styles')
-rw-r--r-- | src/plugins/styles/mac/qmacstyle_mac.mm | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 81835b7c63..cf7cf18c17 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -150,6 +150,16 @@ static QWindow *qt_getWindow(const QWidget *widget) QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver); @implementation NotificationReceiver +{ + QMacStylePrivate *privateStyle; +} + +- (instancetype)initWithPrivateStyle:(QMacStylePrivate *)style +{ + if (self = [super init]) + privateStyle = style; + return self; +} - (void)scrollBarStyleDidChange:(NSNotification *)notification { @@ -162,6 +172,23 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver); for (const auto &o : QMacStylePrivate::scrollBars) QCoreApplication::sendEvent(o, &event); } + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object + change:(NSDictionary<NSKeyValueChangeKey, id> *)change context:(void *)context +{ + Q_UNUSED(keyPath); + Q_UNUSED(object); + Q_UNUSED(change); + Q_UNUSED(context); + + Q_ASSERT([keyPath isEqualToString:@"effectiveAppearance"]); + Q_ASSERT(object == NSApp); + + for (NSView *b : privateStyle->cocoaControls) + [b release]; + privateStyle->cocoaControls.clear(); +} + @end @interface QT_MANGLE_NAMESPACE(QIndeterminateProgressIndicator) : NSProgressIndicator @@ -2068,11 +2095,17 @@ QMacStyle::QMacStyle() Q_D(QMacStyle); QMacAutoReleasePool pool; - d->receiver = [[NotificationReceiver alloc] init]; + d->receiver = [[NotificationReceiver alloc] initWithPrivateStyle:d]; [[NSNotificationCenter defaultCenter] addObserver:d->receiver selector:@selector(scrollBarStyleDidChange:) name:NSPreferredScrollerStyleDidChangeNotification object:nil]; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14) + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave) { + [NSApplication.sharedApplication addObserver:d->receiver forKeyPath:@"effectiveAppearance" + options:NSKeyValueObservingOptionNew context:nullptr]; + } +#endif } QMacStyle::~QMacStyle() @@ -2081,6 +2114,10 @@ QMacStyle::~QMacStyle() QMacAutoReleasePool pool; [[NSNotificationCenter defaultCenter] removeObserver:d->receiver]; +#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_14) + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave) + [NSApplication.sharedApplication removeObserver:d->receiver forKeyPath:@"effectiveAppearance"]; +#endif [d->receiver release]; } |