diff options
author | Doris Verria <doris.verria@qt.io> | 2022-10-04 14:21:03 +0200 |
---|---|---|
committer | Doris Verria <doris.verria@qt.io> | 2022-10-10 15:48:16 +0200 |
commit | abbd9c91f5309924ac707706e3483747f44149a0 (patch) | |
tree | 6ac1c1eda7afb38c2814eaf9efee7f95a031df8d /src/plugins/platforms/ios/qiostheme.mm | |
parent | 9e7f91781d41ba588efac695c74e5304ec15625d (diff) |
QIOSTheme: Set appearance based on UIScreen if no windows created yet
Set the theme's appearance based on the UIScreen's, which follows the
app's or system's configuration, if no UIWindows are created yet.
The UIWindow and UIScreen will have the same appearance (the
traitCollection change is propagated hierarchically from screen to
window) unless UIWindow's overrideUserStyleInterface is explicitly
set to differ from that of the screen. In that case,
traitCollectionDidChange will be called for the window (but not the
screen) and when we update the palette calling the UIColor API, the
colors will be resolved based on
UITraitCollection.currentTraitCollection property, which follows the
window's appearance. That is why we need to set the theme's appearance
based on the window's.
Change-Id: I43207f351559fb82efc2f281eafb3cd1c96bbf75
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/ios/qiostheme.mm')
-rw-r--r-- | src/plugins/platforms/ios/qiostheme.mm | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/plugins/platforms/ios/qiostheme.mm b/src/plugins/platforms/ios/qiostheme.mm index 62ba4d669b..408c59b2cb 100644 --- a/src/plugins/platforms/ios/qiostheme.mm +++ b/src/plugins/platforms/ios/qiostheme.mm @@ -134,13 +134,17 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const Qt::Appearance QIOSTheme::appearance() const { + UIUserInterfaceStyle appearance = UIUserInterfaceStyleUnspecified; + // Set the appearance based on the UIWindow + // Fallback to the UIScreen if no window is created yet if (UIWindow *window = qt_apple_sharedApplication().windows.lastObject) { - return window.traitCollection.userInterfaceStyle - == UIUserInterfaceStyleDark - ? Qt::Appearance::Dark - : Qt::Appearance::Light; + appearance = window.traitCollection.userInterfaceStyle; + } else { + appearance = UIScreen.mainScreen.traitCollection.userInterfaceStyle; } - return Qt::Appearance::Unknown; + return appearance == UIUserInterfaceStyleDark + ? Qt::Appearance::Dark + : Qt::Appearance::Light; } const QFont *QIOSTheme::font(Font type) const |