diff --git a/src/main.cpp b/src/main.cpp index 60cb824a7ef..651a1d1102b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -142,6 +143,26 @@ void adjustScaleFactor(CmdlineArgs* pArgs) { } } +void applyStyleOverride(CmdlineArgs* pArgs) { + if (!pArgs->getStyle().isEmpty()) { + qDebug() << "Default style is overwritten by command line argument " + "-style" + << pArgs->getStyle(); + QApplication::setStyle(pArgs->getStyle()); + return; + } + if (qEnvironmentVariableIsSet("QT_STYLE_OVERRIDE")) { + QString styleOverride = QString::fromLocal8Bit(qgetenv("QT_STYLE_OVERRIDE")); + if (!styleOverride.isEmpty()) { + // The environment variable overrides the command line option + qDebug() << "Default style is overwritten by env variable " + "QT_STYLE_OVERRIDE" + << styleOverride; + QApplication::setStyle(styleOverride); + } + } +} + } // anonymous namespace int main(int argc, char * argv[]) { @@ -208,6 +229,21 @@ int main(int argc, char * argv[]) { MixxxApplication app(argc, argv); +#if defined(Q_OS_WIN) + // The Mixxx style is based on Qt's WindowsVista style + QApplication::setStyle("windowsvista"); +#endif + + applyStyleOverride(&args); + + qInfo() << "Selected Qt style:" << QApplication::style()->objectName(); + +#if defined(Q_OS_WIN) + if (QApplication::style()->objectName() != "windowsvista") { + qWarning() << "Qt style for Windows is not set to 'windowsvista'. GUI might look broken!"; + } +#endif + #ifdef Q_OS_MACOS // TODO: At this point it is too late to provide the same settings path to all components // and too early to log errors and give users advises in their system language. diff --git a/src/util/cmdlineargs.cpp b/src/util/cmdlineargs.cpp index e72f90cade7..524854229b4 100644 --- a/src/util/cmdlineargs.cpp +++ b/src/util/cmdlineargs.cpp @@ -350,6 +350,15 @@ bool CmdlineArgs::parse(const QStringList& arguments, CmdlineArgs::ParseMode mod parser.addOption(debugAssertBreak); parser.addOption(debugAssertBreakDeprecated); + const QCommandLineOption styleOption(QStringLiteral("style"), + forUserFeedback + ? QCoreApplication::translate("CmdlineArgs", + "Sets the application GUI style. Possible values " + "depend on your system configuration.") + : QString(), + QStringLiteral("style")); + parser.addOption(styleOption); + const QCommandLineOption helpOption = parser.addHelpOption(); const QCommandLineOption versionOption = parser.addVersionOption(); @@ -489,5 +498,9 @@ bool CmdlineArgs::parse(const QStringList& arguments, CmdlineArgs::ParseMode mod fputs("Unknown argument for for color.\n", stdout); } + if (parser.isSet(styleOption)) { + m_styleName = parser.value(styleOption); + } + return true; } diff --git a/src/util/cmdlineargs.h b/src/util/cmdlineargs.h index 9ac42607ec0..08980b38de8 100644 --- a/src/util/cmdlineargs.h +++ b/src/util/cmdlineargs.h @@ -71,6 +71,10 @@ class CmdlineArgs final { const QString& getResourcePath() const { return m_resourcePath; } const QString& getTimelinePath() const { return m_timelinePath; } + const QString& getStyle() const { + return m_styleName; + } + void setScaleFactor(double scaleFactor) { m_scaleFactor = scaleFactor; } @@ -110,4 +114,5 @@ class CmdlineArgs final { QString m_settingsPath; QString m_resourcePath; QString m_timelinePath; + QString m_styleName; };