Qt: Work around theme switching issue in 6.4.0

This commit is contained in:
Connor McLaughlin 2023-01-11 20:23:19 +10:00
parent 7c6071dfe1
commit a56ce290d4

View File

@ -66,6 +66,7 @@ static const char* DEFAULT_THEME_NAME = "darkfusion";
MainWindow* g_main_window = nullptr; MainWindow* g_main_window = nullptr;
static QString s_unthemed_style_name; static QString s_unthemed_style_name;
static QPalette s_unthemed_palette;
static bool s_unthemed_style_name_set; static bool s_unthemed_style_name_set;
#if defined(_WIN32) || defined(__APPLE__) #if defined(_WIN32) || defined(__APPLE__)
@ -123,6 +124,7 @@ void MainWindow::updateApplicationTheme()
{ {
s_unthemed_style_name_set = true; s_unthemed_style_name_set = true;
s_unthemed_style_name = QApplication::style()->objectName(); s_unthemed_style_name = QApplication::style()->objectName();
s_unthemed_palette = QApplication::style()->standardPalette();
} }
setStyleFromSettings(); setStyleFromSettings();
@ -2074,7 +2076,7 @@ void MainWindow::setStyleFromSettings()
if (theme == "qdarkstyle") if (theme == "qdarkstyle")
{ {
qApp->setStyle(s_unthemed_style_name); qApp->setStyle(s_unthemed_style_name);
qApp->setPalette(QApplication::style()->standardPalette()); qApp->setPalette(s_unthemed_palette);
QFile f(QStringLiteral(":qdarkstyle/style.qss")); QFile f(QStringLiteral(":qdarkstyle/style.qss"));
if (f.open(QFile::ReadOnly | QFile::Text)) if (f.open(QFile::ReadOnly | QFile::Text))
@ -2082,7 +2084,7 @@ void MainWindow::setStyleFromSettings()
} }
else if (theme == "fusion") else if (theme == "fusion")
{ {
qApp->setPalette(QApplication::style()->standardPalette()); qApp->setPalette(s_unthemed_palette);
qApp->setStyleSheet(QString()); qApp->setStyleSheet(QString());
qApp->setStyle(QStyleFactory::create("Fusion")); qApp->setStyle(QStyleFactory::create("Fusion"));
} }
@ -2161,7 +2163,7 @@ void MainWindow::setStyleFromSettings()
} }
else else
{ {
qApp->setPalette(QApplication::style()->standardPalette()); qApp->setPalette(s_unthemed_palette);
qApp->setStyleSheet(QString()); qApp->setStyleSheet(QString());
qApp->setStyle(s_unthemed_style_name); qApp->setStyle(s_unthemed_style_name);
} }