From a56ce290d4d4b10d1b1bacad1638e896f872b9ef Mon Sep 17 00:00:00 2001
From: Connor McLaughlin <stenzek@gmail.com>
Date: Wed, 11 Jan 2023 20:23:19 +1000
Subject: [PATCH] Qt: Work around theme switching issue in 6.4.0

---
 src/duckstation-qt/mainwindow.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

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