diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index d0bb4a2b85c..17d96ec2ac0 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -52,6 +52,12 @@ namespace Qt { Dark, }; + enum class ColorScheme { + Unknown, + Light, + Dark, + }; + enum MouseButton { NoButton = 0x00000000, LeftButton = 0x00000001, @@ -1758,6 +1764,7 @@ namespace Qt { Q_ENUM_NS(CursorShape) Q_ENUM_NS(GlobalColor) Q_ENUM_NS(Appearance) + Q_ENUM_NS(ColorScheme) Q_ENUM_NS(AspectRatioMode) Q_ENUM_NS(TransformationMode) Q_FLAG_NS(ImageConversionFlags) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 2dd2ac04057..c3489b08513 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2611,6 +2611,12 @@ Qt::Appearance QGuiApplicationPrivate::appearance() : Qt::Appearance::Unknown; } +Qt::ColorScheme QGuiApplicationPrivate::colorScheme() +{ + return platformTheme() ? platformTheme()->colorScheme() + : Qt::ColorScheme::Unknown; +} + void QGuiApplicationPrivate::handleThemeChanged() { updatePalette(); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 46bc504f5f6..47228a0738b 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -314,6 +314,7 @@ private: friend class QDragManager; static Qt::Appearance appearance(); + static Qt::ColorScheme colorScheme(); static QGuiApplicationPrivate *self; static int m_fakeMouseSourcePointId; diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 498ecac2cd4..a7b9f30d56d 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -441,6 +441,11 @@ Qt::Appearance QPlatformTheme::appearance() const return Qt::Appearance::Unknown; } +Qt::ColorScheme QPlatformTheme::colorScheme() const +{ + return Qt::ColorScheme(appearance()); +} + 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 10a3246da8e..fd9d1a93249 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -294,6 +294,7 @@ public: #endif virtual Qt::Appearance appearance() const; + virtual Qt::ColorScheme colorScheme() const; virtual const QPalette *palette(Palette type = SystemPalette) const; diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp index 69de74e2c30..ea30741dbe3 100644 --- a/src/gui/kernel/qstylehints.cpp +++ b/src/gui/kernel/qstylehints.cpp @@ -132,6 +132,11 @@ Qt::Appearance QStyleHints::appearance() const return d_func()->appearance(); } +Qt::ColorScheme QStyleHints::colorScheme() const +{ + return Qt::ColorScheme(appearance()); +} + /*! Sets the \a mousePressAndHoldInterval. \internal diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h index 779bed67d8e..cae5a64f858 100644 --- a/src/gui/kernel/qstylehints.h +++ b/src/gui/kernel/qstylehints.h @@ -53,6 +53,7 @@ class Q_GUI_EXPORT QStyleHints : public QObject FINAL) Q_PROPERTY(int touchDoubleTapDistance READ touchDoubleTapDistance STORED false CONSTANT FINAL) Q_PROPERTY(Qt::Appearance appearance READ appearance NOTIFY appearanceChanged FINAL) + Q_PROPERTY(Qt::ColorScheme colorScheme READ colorScheme NOTIFY colorSchemeChanged FINAL) public: void setMouseDoubleClickInterval(int mouseDoubleClickInterval); @@ -94,6 +95,7 @@ public: void setMouseQuickSelectionThreshold(int threshold); int mouseQuickSelectionThreshold() const; Qt::Appearance appearance() const; + Qt::ColorScheme colorScheme() const; Q_SIGNALS: void cursorFlashTimeChanged(int cursorFlashTime); @@ -108,6 +110,7 @@ Q_SIGNALS: void wheelScrollLinesChanged(int scrollLines); void mouseQuickSelectionThresholdChanged(int threshold); void appearanceChanged(Qt::Appearance appearance); + void colorSchemeChanged(Qt::ColorScheme colorScheme); private: friend class QGuiApplication;