diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index ce0dedc88d..beaaa3fbfc 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -177,8 +178,16 @@ static QIOSScreen* qtPlatformScreenFor(UIScreen *uiScreen) { [super traitCollectionDidChange:previousTraitCollection]; + Qt::Appearance appearance = self.traitCollection.userInterfaceStyle + == UIUserInterfaceStyleDark + ? Qt::Appearance::Dark + : Qt::Appearance::Light; + if (self.screen == UIScreen.mainScreen) { - if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle) { + // Check if the current userInterfaceStyle reports a different appearance than + // the platformTheme's appearance. We might have set that one based on the UIScreen + if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle + || QGuiApplicationPrivate::platformTheme()->appearance() != appearance) { QIOSTheme::initializeSystemPalette(); QWindowSystemInterface::handleThemeChange(); } 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