aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2025-07-02 22:11:56 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2025-07-10 12:24:01 +0000
commitc511dcdea5fd1b4ccb8ce5d1691673b63b237990 (patch)
tree35f7186bec75b0b2428fb2465f2aa5b977ddf532 /src
parent20c45d3e6b416a6759d2b2dbbc9ad9c10d90562f (diff)
iOS Style: Resolve UIColor-s with appropriate trait collection
QQuickIOSSTheme::intialize() is called when first setting up the theme (and its palette) for the iOS style, as well as whenever the color scheme gets updated. This is a function that is called on the QML thread by the style plugin, as the QQuickTheme also lives in the QML thread. In this function we resolve the palette colors through the dynamic UIColor-s, which update based on the currentTraitCollection. However, it is not safe to rely on the value of the currentTraitCollection property outside the main thread, or even in functions other than the documented methods where UIKit sets the property as it may be invalid. To fix, construct a trait collection based on the current color scheme and resolve the UIColor against it. Fixes: QTBUG-138200 Pick-to: 6.8 Change-Id: I404428844bc2e3b35be5746746d8d21bde3b3832 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit 4eee74ecf71b1ed3c1b37683790c46fbe0d73ac3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 50e0ecc8af8095f115ab763fc4a4634f353fb193)
Diffstat (limited to 'src')
-rw-r--r--src/quickcontrols/ios/qquickiostheme.mm30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/quickcontrols/ios/qquickiostheme.mm b/src/quickcontrols/ios/qquickiostheme.mm
index 2f7c84ae7e..33012fed59 100644
--- a/src/quickcontrols/ios/qquickiostheme.mm
+++ b/src/quickcontrols/ios/qquickiostheme.mm
@@ -11,6 +11,8 @@
#include <UIKit/UIInterface.h>
#endif
+#include <QtGui/qguiapplication.h>
+#include <QtGui/qstylehints.h>
#include <QtQuickTemplates2/private/qquicktheme_p.h>
#include <QtQuickControls2/private/qquickstyle_p.h>
@@ -31,20 +33,24 @@ void QQuickIOSTheme::initialize(QQuickTheme *theme)
QColor lightGray;
QColor gray;
QColor darkGray;
+
+ bool isDarkSystemTheme = QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark;
#ifdef Q_OS_IOS
- window = qt_mac_toQColor(UIColor.systemGroupedBackgroundColor.CGColor);
- base = qt_mac_toQColor(UIColor.secondarySystemGroupedBackgroundColor.CGColor);
- text = qt_mac_toQColor(UIColor.labelColor.CGColor);
- disabledText = qt_mac_toQColor(UIColor.tertiaryLabelColor.CGColor);
- placeholderText = qt_mac_toQColor(UIColor.placeholderTextColor.CGColor);
- button = qt_mac_toQColor(UIColor.systemBlueColor.CGColor);
- disabledButton = qt_mac_toQColor(UIColor.tertiarySystemFillColor.CGColor);
- white = qt_mac_toQColor(UIColor.whiteColor.CGColor);
- lightGray = qt_mac_toQColor(UIColor.systemGray6Color.CGColor);
- gray = qt_mac_toQColor(UIColor.opaqueSeparatorColor.CGColor);
- darkGray = qt_mac_toQColor(UIColor.systemGrayColor.CGColor);
+ UIUserInterfaceStyle style = isDarkSystemTheme ? UIUserInterfaceStyleDark : UIUserInterfaceStyleLight;
+ UITraitCollection *traitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:style];
+
+ window = qt_mac_toQColor([UIColor.systemGroupedBackgroundColor resolvedColorWithTraitCollection:traitCollection].CGColor);
+ base = qt_mac_toQColor([UIColor.secondarySystemGroupedBackgroundColor resolvedColorWithTraitCollection:traitCollection].CGColor);
+ text = qt_mac_toQColor([UIColor.labelColor resolvedColorWithTraitCollection:traitCollection].CGColor);
+ disabledText = qt_mac_toQColor([UIColor.tertiaryLabelColor resolvedColorWithTraitCollection:traitCollection].CGColor);
+ placeholderText = qt_mac_toQColor([UIColor.placeholderTextColor resolvedColorWithTraitCollection:traitCollection].CGColor);
+ button = qt_mac_toQColor([UIColor.systemBlueColor resolvedColorWithTraitCollection:traitCollection].CGColor);
+ disabledButton = qt_mac_toQColor([UIColor.tertiarySystemFillColor resolvedColorWithTraitCollection:traitCollection].CGColor);
+ white = qt_mac_toQColor([UIColor.whiteColor resolvedColorWithTraitCollection:traitCollection].CGColor);
+ lightGray = qt_mac_toQColor([UIColor.systemGray6Color resolvedColorWithTraitCollection:traitCollection].CGColor);
+ gray = qt_mac_toQColor([UIColor.opaqueSeparatorColor resolvedColorWithTraitCollection:traitCollection].CGColor);
+ darkGray = qt_mac_toQColor([UIColor.systemGrayColor resolvedColorWithTraitCollection:traitCollection].CGColor);
#else
- bool isDarkSystemTheme = QQuickStylePrivate::isDarkSystemTheme();
window = isDarkSystemTheme ? QColor(qRgba(0, 0, 0, 255)) : QColor(qRgba(242, 242, 247, 255));
base = isDarkSystemTheme ? QColor(qRgba(28, 28, 30, 255)) : QColor(Qt::white);
text = isDarkSystemTheme ? QColor(Qt::white) : QColor(Qt::black);