Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt6.8: Ensure Mixxx uses "windowsvista" Qt style on Windows #14228

Open
wants to merge 1 commit into
base: 2.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QPixmapCache>
#include <QString>
#include <QStringList>
#include <QStyle>
#include <QTextCodec>
#include <QThread>
#include <QtDebug>
Expand Down Expand Up @@ -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());
JoergAtGithub marked this conversation as resolved.
Show resolved Hide resolved
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[]) {
Expand Down Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/util/cmdlineargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions src/util/cmdlineargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -110,4 +114,5 @@ class CmdlineArgs final {
QString m_settingsPath;
QString m_resourcePath;
QString m_timelinePath;
QString m_styleName;
};
Loading