aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/basic/qquickbasictheme.cpp
diff options
context:
space:
mode:
authorMohammadHossein Qanbari <mohammad.qanbari@qt.io>2025-03-26 13:51:11 +0100
committerMohammadHossein Qanbari <mohammad.qanbari@qt.io>2025-04-05 02:14:36 +0200
commit52141b34ecd16b33e9879fc1047c6f9c3dfde6da (patch)
tree29cb4d7085e7979ea82ecc7b73c675c397f9a864 /src/quickcontrols/basic/qquickbasictheme.cpp
parent0e92a8e0683e2d388a61aac85509a8efbc16cd01 (diff)
Basic Style: Add support for dark mode color scheme
Previously, the basic style did not respect the system's dark mode settings because the palette initialized by QQuickBasicTheme lacked definitions for dark mode colors. This commit updates the palette initialization to dynamically set colors based on the current system color scheme. Additionally, the palette is reinitialized whenever the system color scheme changes. The controls gallery example has been updated to demonstrate the new functionality. [ChangeLog][Controls][Basic] Basic style supports dark mode now. Fixes: QTBUG-135207 Change-Id: I2d6a74b407a7981905a9b86e97004cf0609a4bf0 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quickcontrols/basic/qquickbasictheme.cpp')
-rw-r--r--src/quickcontrols/basic/qquickbasictheme.cpp84
1 files changed, 60 insertions, 24 deletions
diff --git a/src/quickcontrols/basic/qquickbasictheme.cpp b/src/quickcontrols/basic/qquickbasictheme.cpp
index 7884ad102e..735b4e9569 100644
--- a/src/quickcontrols/basic/qquickbasictheme.cpp
+++ b/src/quickcontrols/basic/qquickbasictheme.cpp
@@ -4,6 +4,7 @@
#include "qquickbasictheme_p.h"
#include <QtQuickTemplates2/private/qquicktheme_p.h>
+#include <QtQuickControls2/private/qquickstyle_p.h>
QT_BEGIN_NAMESPACE
@@ -11,48 +12,83 @@ void QQuickBasicTheme::initialize(QQuickTheme *theme)
{
QPalette systemPalette;
- systemPalette.setColor(QPalette::Base, QColor::fromRgba(0xFFFFFFFF));
- systemPalette.setColor(QPalette::Disabled, QPalette::Base, QColor::fromRgba(0xFFD6D6D6));
+ const bool isDarkSystemTheme = QQuickStylePrivate::isDarkSystemTheme();
- systemPalette.setColor(QPalette::Button, QColor::fromRgba(0xFFE0E0E0));
+ const QRgb base(isDarkSystemTheme ? 0xFF000000 : 0xFFFFFFFF);
+ const QRgb disabledBase(isDarkSystemTheme ? 0xFF292929 : 0xFFD6D6D6);
+ const QRgb button(isDarkSystemTheme ? 0xFF2F2F2F : 0xFFE0E0E0);
+ const QRgb buttonText(isDarkSystemTheme ? 0xFFD4D6D8 : 0xFF26282A);
+ const QRgb disabledButtonText(isDarkSystemTheme ? 0x4DD4D6D8 : 0x4D26282A);
+ const QRgb brightText(isDarkSystemTheme ? 0xFF000000 : 0xFFFFFFFF);
+ const QRgb disabledBrightText(isDarkSystemTheme ? 0x4D000000 : 0x4DFFFFFF);
+ const QRgb dark(isDarkSystemTheme ? 0xFFC8C9CB : 0xFF353637);
+ const QRgb highlight(isDarkSystemTheme ? 0xFF0D69F2 : 0xFF0066FF);
+ const QRgb disabledHighlight(isDarkSystemTheme ? 0xFF01060F : 0xFFF0F6FF);
+ const QRgb highlightedText(isDarkSystemTheme ? 0xFFFDFDFD : 0xFF090909);
+ const QRgb light(isDarkSystemTheme ? 0xFF1A1A1A : 0xFFF6F6F6);
+ const QRgb link(isDarkSystemTheme ? 0xFF2F86B1 : 0xFF45A7D7);
+ const QRgb mid(isDarkSystemTheme ? 0xFF626262 : 0xFFBDBDBD);
+ const QRgb midlight(isDarkSystemTheme ? 0xFF2C2C2C : 0xFFE4E4E4);
+ const QRgb text(isDarkSystemTheme ? 0xFFEFF0F2 : 0xFF353637);
+ const QRgb disabledText(isDarkSystemTheme ? 0x7FC8C9CB : 0x7F353637);
+ const QRgb shadow(isDarkSystemTheme ? 0xFF28282A : 0xFF28282A);
+ const QRgb toolTipBase(isDarkSystemTheme ? 0xFF000000 : 0xFFFFFFFF);
+ const QRgb toolTipText(isDarkSystemTheme ? 0xFFFFFFFF : 0xFF000000);
+ const QRgb window(isDarkSystemTheme ? 0xFF000000 : 0xFFFFFFFF);
+ const QRgb windowText(isDarkSystemTheme ? 0xFFD4D6D8 : 0xFF26282A);
+ const QRgb disabledWindowText(isDarkSystemTheme ? 0xFF3F4040 : 0xFFBDBEBF);
+ const QRgb placeholderText(isDarkSystemTheme ? 0x88C8C9CB : 0x88353637);
- systemPalette.setColor(QPalette::ButtonText, QColor::fromRgba(0xFF26282A));
- systemPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor::fromRgba(0x4D26282A));
+ systemPalette.setColor(QPalette::Base, base);
+ systemPalette.setColor(QPalette::Disabled, QPalette::Base, disabledBase);
- systemPalette.setColor(QPalette::BrightText, QColor::fromRgba(0xFFFFFFFF));
- systemPalette.setColor(QPalette::Disabled, QPalette::BrightText, QColor::fromRgba(0x4DFFFFFF));
+ systemPalette.setColor(QPalette::Button, button);
- systemPalette.setColor(QPalette::Dark, QColor::fromRgba(0xFF353637));
+ systemPalette.setColor(QPalette::ButtonText, buttonText);
+ systemPalette.setColor(QPalette::Disabled, QPalette::ButtonText, disabledButtonText);
- systemPalette.setColor(QPalette::Highlight, QColor::fromRgba(0xFF0066FF));
- systemPalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor::fromRgba(0xFFF0F6FF));
+ systemPalette.setColor(QPalette::BrightText, brightText);
+ systemPalette.setColor(QPalette::Disabled, QPalette::BrightText, disabledBrightText);
- systemPalette.setColor(QPalette::HighlightedText, QColor::fromRgba(0xFF090909));
+ systemPalette.setColor(QPalette::Dark, dark);
- systemPalette.setColor(QPalette::Light, QColor::fromRgba(0xFFF6F6F6));
+ systemPalette.setColor(QPalette::Highlight, highlight);
+ systemPalette.setColor(QPalette::Disabled, QPalette::Highlight, disabledHighlight);
- systemPalette.setColor(QPalette::Link, QColor::fromRgba(0xFF45A7D7));
+ systemPalette.setColor(QPalette::HighlightedText, highlightedText);
- systemPalette.setColor(QPalette::Mid, QColor::fromRgba(0xFFBDBDBD));
+ systemPalette.setColor(QPalette::Light, light);
- systemPalette.setColor(QPalette::Midlight, QColor::fromRgba(0xFFE4E4E4));
+ systemPalette.setColor(QPalette::Link, link);
- systemPalette.setColor(QPalette::Text, QColor::fromRgba(0xFF353637));
- systemPalette.setColor(QPalette::Disabled, QPalette::Text, QColor::fromRgba(0x7F353637));
+ systemPalette.setColor(QPalette::Mid, mid);
- systemPalette.setColor(QPalette::Shadow, QColor::fromRgba(0xFF28282A));
+ systemPalette.setColor(QPalette::Midlight, midlight);
- systemPalette.setColor(QPalette::ToolTipBase, QColor::fromRgba(0xFFFFFFFF));
- systemPalette.setColor(QPalette::ToolTipText, QColor::fromRgba(0xFF000000));
+ systemPalette.setColor(QPalette::Text, text);
+ systemPalette.setColor(QPalette::Disabled, QPalette::Text, disabledText);
- systemPalette.setColor(QPalette::Window, QColor::fromRgba(0xFFFFFFFF));
+ systemPalette.setColor(QPalette::Shadow, shadow);
- systemPalette.setColor(QPalette::WindowText, QColor::fromRgba(0xFF26282A));
- systemPalette.setColor(QPalette::Disabled, QPalette::WindowText, QColor::fromRgba(0xFFBDBEBF));
+ systemPalette.setColor(QPalette::ToolTipBase, toolTipBase);
+ systemPalette.setColor(QPalette::ToolTipText, toolTipText);
- systemPalette.setColor(QPalette::PlaceholderText, QColor::fromRgba(0x88353637));
+ systemPalette.setColor(QPalette::Window, window);
+
+ systemPalette.setColor(QPalette::WindowText, windowText);
+ systemPalette.setColor(QPalette::Disabled, QPalette::WindowText, disabledWindowText);
+
+ systemPalette.setColor(QPalette::PlaceholderText, placeholderText);
theme->setPalette(QQuickTheme::System, systemPalette);
}
+void QQuickBasicTheme::updateTheme()
+{
+ QQuickTheme *theme = QQuickTheme::instance();
+ if (!theme)
+ return;
+ initialize(theme);
+}
+
QT_END_NAMESPACE