Change default Qt quick control style depending on the platform.
authorCamila Ayres <hello@camilasan.com>
Wed, 7 Aug 2024 15:05:29 +0000 (17:05 +0200)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 6 Sep 2024 08:55:29 +0000 (10:55 +0200)
Signed-off-by: Camila Ayres <hello@camilasan.com>
src/gui/main.cpp

index 14b55dab7dc35169f5ca9ac423b08f060bafa4cc..b1794106a5d4e5adc8a9f4bd4d9f1c07e49d5d6b 100644 (file)
@@ -70,10 +70,28 @@ int main(int argc, char **argv)
     QSurfaceFormat::setDefaultFormat(surfaceFormat);
 
     QQuickWindow::setTextRenderType(QQuickWindow::NativeTextRendering);
-    QQuickStyle::setStyle(QStringLiteral("Fusion"));
+
+    auto style = QStringLiteral("Fusion");
+
+#ifdef Q_OS_MAC
+    style = QStringLiteral("macOS");
+#endif
 
     OCC::Application app(argc, argv);
 
+#ifdef Q_OS_WIN
+    // The Windows style still has pixelated elements with Qt 5.6,
+    // it's recommended to use the Fusion style in this case, even
+    // though it looks slightly less native. Check here after the
+    // QApplication was constructed, but before any QWidget is
+    // constructed.
+    if (app.devicePixelRatio() > 1) {
+        style = "Windows";
+    }
+#endif // Q_OS_WIN
+
+    QQuickStyle::setStyle(style);
+
 #ifndef Q_OS_WIN
     signal(SIGPIPE, SIG_IGN);
 #endif