Skip to content

Commit

Permalink
Qt: Work around theme switching bug
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 19, 2024
1 parent 304f69e commit b2577ef
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/duckstation-qt/qtthemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ void QtHost::SetStyleFromSettings()
{
const std::string theme = Host::GetBaseStringSettingValue("UI", "Theme", InterfaceSettingsWidget::DEFAULT_THEME_NAME);

// setPalette() shouldn't be necessary, as the documentation claims that setStyle() resets the palette, but it
// is here, to work around a bug in 6.4.x and 6.5.x where the palette doesn't restore after changing themes.
qApp->setPalette(s_unthemed_palette);

if (theme == "qdarkstyle")
{
qApp->setStyle(s_unthemed_style_name);
qApp->setPalette(s_unthemed_palette);
qApp->setStyleSheet(QString());

QFile f(QStringLiteral(":qdarkstyle/style.qss"));
Expand All @@ -58,13 +55,13 @@ void QtHost::SetStyleFromSettings()
else if (theme == "fusion")
{
qApp->setStyle(QStyleFactory::create("Fusion"));
qApp->setPalette(s_unthemed_palette);
qApp->setStyleSheet(QString());
}
else if (theme == "darkfusion")
{
// adapted from https://gist.github.com/QuantumCD/6245215
qApp->setStyle(QStyleFactory::create("Fusion"));
qApp->setStyleSheet(QString());

const QColor lighterGray(75, 75, 75);
const QColor darkGray(53, 53, 53);
Expand Down Expand Up @@ -94,12 +91,12 @@ void QtHost::SetStyleFromSettings()
darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray);

qApp->setPalette(darkPalette);
qApp->setStyleSheet(QString());
}
else if (theme == "darkfusionblue")
{
// adapted from https://gist.github.com/QuantumCD/6245215
qApp->setStyle(QStyleFactory::create("Fusion"));
qApp->setStyleSheet(QString());

// const QColor lighterGray(75, 75, 75);
const QColor darkGray(53, 53, 53);
Expand Down Expand Up @@ -130,14 +127,14 @@ void QtHost::SetStyleFromSettings()
darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray);

qApp->setPalette(darkPalette);
qApp->setStyleSheet(QString());
}
else if (theme == "cobaltsky")
{
// Custom palette by KamFretoZ, A soothing deep royal blue
// that are meant to be easy on the eyes as the main color.
// Alternative dark theme.
qApp->setStyle(QStyleFactory::create("Fusion"));
qApp->setStyleSheet(QString());

const QColor gray(150, 150, 150);
const QColor royalBlue(29, 41, 81);
Expand Down Expand Up @@ -167,11 +164,11 @@ void QtHost::SetStyleFromSettings()
darkPalette.setColor(QPalette::Disabled, QPalette::Light, gray);

qApp->setPalette(darkPalette);
qApp->setStyleSheet(QString());
}
else if (theme == "greymatter")
{
qApp->setStyle(QStyleFactory::create("Fusion"));
qApp->setStyleSheet(QString());

const QColor darkGray(46, 52, 64);
const QColor lighterGray(59, 66, 82);
Expand Down Expand Up @@ -200,11 +197,11 @@ void QtHost::SetStyleFromSettings()
darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray);

qApp->setPalette(darkPalette);
qApp->setStyleSheet(QString());
}
else if (theme == "darkruby")
{
qApp->setStyle(QStyleFactory::create("Fusion"));
qApp->setStyleSheet(QString());

const QColor gray(128, 128, 128);
const QColor slate(18, 18, 18);
Expand All @@ -231,11 +228,11 @@ void QtHost::SetStyleFromSettings()
darkPalette.setColor(QPalette::Disabled, QPalette::Light, slate.lighter());

qApp->setPalette(darkPalette);
qApp->setStyleSheet(QString());
}
else if (theme == "purplerain")
{
qApp->setStyle(QStyleFactory::create("Fusion"));
qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #505a70; border: 1px solid white; }");

const QColor darkPurple(73, 41, 121);
const QColor darkerPurple(53, 29, 87);
Expand Down Expand Up @@ -263,17 +260,20 @@ void QtHost::SetStyleFromSettings()
darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkPurple);

qApp->setPalette(darkPalette);
qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #505a70; border: 1px solid white; }");
}
#ifdef _WIN32
else if (theme == "windowsvista")
{
qApp->setStyle(QStyleFactory::create("windowsvista"));
qApp->setPalette(s_unthemed_palette);
qApp->setStyleSheet(QString());
}
#endif
else
{
qApp->setStyle(s_unthemed_style_name);
qApp->setPalette(s_unthemed_palette);
qApp->setStyleSheet(QString());
}
}
Expand Down

0 comments on commit b2577ef

Please sign in to comment.