Add QPlatformTheme::Appearance for detecting light/dark modes
And implement it on Windows and macOS. Fixes: QTBUG-83908 Fixes: QTBUG-94859 Change-Id: I7b0c062adf5d4dbaefa64c862ab8ab1348809d71 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
b6200de5d0
commit
2248487c6c
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 ?
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user