From b3359dadc9dd117cd3cd2b856767846dfa973c61 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 4 Jul 2020 15:54:26 +1000 Subject: [PATCH] Qt: Save original style name for restoring after theme switch --- src/duckstation-qt/mainwindow.cpp | 12 ++++++------ src/duckstation-qt/mainwindow.h | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 4bd9de1b8..f481a2678 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -35,7 +35,8 @@ ALWAYS_INLINE static QString getWindowTitle() return QStringLiteral("DuckStation %1 (%2)").arg(g_scm_tag_str).arg(g_scm_branch_str); } -MainWindow::MainWindow(QtHostInterface* host_interface) : QMainWindow(nullptr), m_host_interface(host_interface) +MainWindow::MainWindow(QtHostInterface* host_interface) + : QMainWindow(nullptr), m_unthemed_style_name(QApplication::style()->objectName()), m_host_interface(host_interface) { m_host_interface->setMainWindow(this); @@ -649,6 +650,9 @@ void MainWindow::updateTheme() QString theme = m_host_interface->getSettingValue(QStringLiteral("UI/Theme"), QStringLiteral("default")).toString(); if (theme == QStringLiteral("qdarkstyle")) { + qApp->setStyle(m_unthemed_style_name); + qApp->setPalette(QApplication::style()->standardPalette()); + QFile f(QStringLiteral(":qdarkstyle/style.qss")); if (f.open(QFile::ReadOnly | QFile::Text)) qApp->setStyleSheet(f.readAll()); @@ -691,12 +695,8 @@ void MainWindow::updateTheme() else { qApp->setPalette(QApplication::style()->standardPalette()); - - QStringList available_styles = QStyleFactory::keys(); - if (!available_styles.empty()) - qApp->setStyle(QStyleFactory::create(available_styles.first())); - qApp->setStyleSheet(QString()); + qApp->setStyle(m_unthemed_style_name); } for (QObject* obj : m_ui.menuSettingsTheme->children()) diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 05c04f96b..82978fbf1 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -80,6 +80,8 @@ private: Ui::MainWindow m_ui; + QString m_unthemed_style_name; + QtHostInterface* m_host_interface = nullptr; GameListWidget* m_game_list_widget = nullptr;