diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 34f7307cd7..f8d580ca79 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -401,6 +401,11 @@ QPlatformDialogHelper *QPlatformTheme::createPlatformDialogHelper(DialogType typ return nullptr; } +QPlatformTheme::Appearance QPlatformTheme::appearance() const +{ + return Appearance::Unknown; +} + const QPalette *QPlatformTheme::palette(Palette type) const { Q_D(const QPlatformTheme); diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 0b6c0254f0..011f8d548c 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -128,6 +128,12 @@ public: MessageDialog }; + enum class Appearance { + Unknown = 0x0000, + Light = 0x0001, + Dark = 0x0002 + }; + enum Palette { SystemPalette, ToolTipPalette, @@ -299,6 +305,8 @@ public: virtual QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const; #endif + virtual Appearance appearance() const; + virtual const QPalette *palette(Palette type = SystemPalette) const; virtual const QFont *font(Font type = SystemFont) const; diff --git a/src/plugins/platforms/cocoa/qcocoatheme.h b/src/plugins/platforms/cocoa/qcocoatheme.h index f6276e3d1a..436ed94351 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.h +++ b/src/plugins/platforms/cocoa/qcocoatheme.h @@ -73,6 +73,7 @@ public: QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions options = {}) const override; QVariant themeHint(ThemeHint hint) const override; + Appearance appearance() const override; QString standardButtonText(int button) const override; QKeySequence standardButtonShortcut(int button) const override; diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index abb2aa03da..8f0f6b90d8 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -533,6 +533,11 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const return QPlatformTheme::themeHint(hint); } +QPlatformTheme::Appearance QCocoaTheme::appearance() const +{ + return qt_mac_applicationIsInDarkMode() ? Appearance::Dark : Appearance::Light; +} + QString QCocoaTheme::standardButtonText(int button) const { return button == QPlatformDialogHelper::Discard ? diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 61a885953a..6fbf4183da 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -529,6 +529,11 @@ QVariant QWindowsTheme::themeHint(ThemeHint hint) const return QPlatformTheme::themeHint(hint); } +QPlatformTheme::Appearance QWindowsTheme::appearance() const +{ + return QWindowsContext::isDarkMode() ? Appearance::Dark : Appearance::Light; +} + void QWindowsTheme::clearPalettes() { qDeleteAll(m_palettes, m_palettes + NPalettes); diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h index af28f2878c..9d5fcc92fe 100644 --- a/src/plugins/platforms/windows/qwindowstheme.h +++ b/src/plugins/platforms/windows/qwindowstheme.h @@ -64,6 +64,9 @@ public: QPlatformSystemTrayIcon *createPlatformSystemTrayIcon() const override; #endif QVariant themeHint(ThemeHint) const override; + + Appearance appearance() const override; + const QPalette *palette(Palette type = SystemPalette) const override { return m_palettes[type]; } const QFont *font(Font type = SystemFont) const override