Apply styles before instantiating Q(Gui)Application

This should fix style on windows
This commit is contained in:
Bart De Vries 2024-03-28 10:20:32 +01:00
parent 1e622c6e1d
commit 92bb03fd76
1 changed files with 10 additions and 2 deletions

View File

@ -22,6 +22,8 @@
#include <QGuiApplication> #include <QGuiApplication>
#else #else
#include <QApplication> #include <QApplication>
#include <QStyle>
#include <QStyleFactory>
#endif #endif
#include <KAboutData> #include <KAboutData>
@ -63,10 +65,17 @@ int main(int argc, char *argv[])
QLoggingCategory::setFilterRules(QStringLiteral("org.kde.*=true")); QLoggingCategory::setFilterRules(QStringLiteral("org.kde.*=true"));
QQuickStyle::setStyle(QStringLiteral("org.kde.breeze")); QQuickStyle::setStyle(QStringLiteral("org.kde.breeze"));
#else #else
QApplication app(argc, argv); #ifdef Q_OS_WINDOWS
// has to be set before instantiating QApplication
QApplication::setStyle(QStringLiteral("Breeze"));
#endif
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
} }
QApplication app(argc, argv);
qDebug() << QStyleFactory::keys() << QApplication::style() << QQuickStyle::name();
#endif #endif
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
@ -75,7 +84,6 @@ int main(int argc, char *argv[])
freopen("CONOUT$", "w", stderr); freopen("CONOUT$", "w", stderr);
} }
QApplication::setStyle(QStringLiteral("breeze"));
auto font = app.font(); auto font = app.font();
font.setPointSize(10); font.setPointSize(10);
app.setFont(font); app.setFont(font);