diff --git a/pcsx2-qt/GameList/GameListModel.cpp b/pcsx2-qt/GameList/GameListModel.cpp index 9c865b85af..17a12ded37 100644 --- a/pcsx2-qt/GameList/GameListModel.cpp +++ b/pcsx2-qt/GameList/GameListModel.cpp @@ -146,6 +146,12 @@ void GameListModel::refreshCovers() refresh(); } +void GameListModel::refreshImages() +{ + loadCommonImages(); + refresh(); +} + int GameListModel::getCoverArtWidth() const { return std::max(static_cast(static_cast(COVER_ART_WIDTH) * m_cover_scale), 1); diff --git a/pcsx2-qt/GameList/GameListModel.h b/pcsx2-qt/GameList/GameListModel.h index 8cc02baed9..5e3d2e4d3b 100644 --- a/pcsx2-qt/GameList/GameListModel.h +++ b/pcsx2-qt/GameList/GameListModel.h @@ -73,6 +73,7 @@ public: int getCoverArtHeight() const; int getCoverArtSpacing() const; void refreshCovers(); + void refreshImages(); private: void loadCommonImages(); diff --git a/pcsx2-qt/GameList/GameListWidget.cpp b/pcsx2-qt/GameList/GameListWidget.cpp index e2d2db15d0..f014b9e499 100644 --- a/pcsx2-qt/GameList/GameListWidget.cpp +++ b/pcsx2-qt/GameList/GameListWidget.cpp @@ -249,6 +249,11 @@ void GameListWidget::cancelRefresh() pxAssertRel(!m_refresh_thread, "Game list thread should be unreferenced by now"); } +void GameListWidget::refreshImages() +{ + m_model->refreshImages(); +} + void GameListWidget::onRefreshProgress(const QString& status, int current, int total) { // switch away from the placeholder while we scan, in case we find anything diff --git a/pcsx2-qt/GameList/GameListWidget.h b/pcsx2-qt/GameList/GameListWidget.h index 1e920adccb..601024ca3f 100644 --- a/pcsx2-qt/GameList/GameListWidget.h +++ b/pcsx2-qt/GameList/GameListWidget.h @@ -56,6 +56,7 @@ public: void refresh(bool invalidate_cache); void cancelRefresh(); + void refreshImages(); bool isShowingGameList() const; bool isShowingGameGrid() const; diff --git a/pcsx2-qt/MainWindow.cpp b/pcsx2-qt/MainWindow.cpp index b2adb6a5d8..e886094860 100644 --- a/pcsx2-qt/MainWindow.cpp +++ b/pcsx2-qt/MainWindow.cpp @@ -84,6 +84,8 @@ const char* MainWindow::DEFAULT_THEME_NAME = "darkfusion"; #endif MainWindow* g_main_window = nullptr; +static QString s_unthemed_style_name; +static bool s_unthemed_style_name_set; #if defined(_WIN32) || defined(__APPLE__) static const bool s_use_central_widget = false; @@ -122,15 +124,12 @@ MainWindow::~MainWindow() void MainWindow::initialize() { - setStyleFromSettings(); - setIconThemeFromStyle(); #ifdef __APPLE__ CocoaTools::AddThemeChangeHandler(this, [](void* ctx) { // This handler is called *before* the style change has propagated far enough for Qt to see it // Use RunOnUIThread to delay until it has - QtHost::RunOnUIThread([ctx = static_cast(ctx)] { - ctx->setStyleFromSettings(); // Qt won't notice the style change without us touching the palette in some way - ctx->setIconThemeFromStyle(); + QtHost::RunOnUIThread([ctx = static_cast(ctx)]{ + ctx->updateTheme();// Qt won't notice the style change without us touching the palette in some way }); }); #endif @@ -399,6 +398,18 @@ void MainWindow::recreate() deleteLater(); } +void MainWindow::updateApplicationTheme() +{ + if (!s_unthemed_style_name_set) + { + s_unthemed_style_name_set = true; + s_unthemed_style_name = QApplication::style()->objectName(); + } + + setStyleFromSettings(); + setIconThemeFromStyle(); +} + void MainWindow::setStyleFromSettings() { const std::string theme(Host::GetBaseStringSettingValue("UI", "Theme", DEFAULT_THEME_NAME)); @@ -682,7 +693,7 @@ void MainWindow::setStyleFromSettings() { qApp->setPalette(QApplication::style()->standardPalette()); qApp->setStyleSheet(QString()); - qApp->setStyle(m_unthemed_style_name); + qApp->setStyle(s_unthemed_style_name); } } @@ -1433,18 +1444,10 @@ void MainWindow::onToolsOpenDataDirectoryTriggered() QtUtils::OpenURL(this, QUrl::fromLocalFile(path)); } -void MainWindow::onThemeChanged() +void MainWindow::updateTheme() { - setStyleFromSettings(); - setIconThemeFromStyle(); - recreate(); -} - -void MainWindow::onThemeChangedFromSettings() -{ - // reopen the settings dialog after recreating - onThemeChanged(); - g_main_window->doSettings(); + updateApplicationTheme(); + m_game_list_widget->refreshImages(); } void MainWindow::onLoggingOptionChanged() @@ -2058,7 +2061,7 @@ SettingsDialog* MainWindow::getSettingsDialog() { m_settings_dialog = new SettingsDialog(this); connect( - m_settings_dialog->getInterfaceSettingsWidget(), &InterfaceSettingsWidget::themeChanged, this, &MainWindow::onThemeChangedFromSettings); + m_settings_dialog->getInterfaceSettingsWidget(), &InterfaceSettingsWidget::themeChanged, this, &MainWindow::updateTheme); } return m_settings_dialog; diff --git a/pcsx2-qt/MainWindow.h b/pcsx2-qt/MainWindow.h index 932ff23582..b0bd38db80 100644 --- a/pcsx2-qt/MainWindow.h +++ b/pcsx2-qt/MainWindow.h @@ -79,6 +79,9 @@ public: explicit MainWindow(const QString& unthemed_style_name); ~MainWindow(); + /// Sets application theme according to settings. + static void updateApplicationTheme(); + void initialize(); void connectVMThreadSignals(EmuThread* thread); void startupUpdateCheck(); @@ -143,8 +146,7 @@ private Q_SLOTS: void onAboutActionTriggered(); void onCheckForUpdatesActionTriggered(); void onToolsOpenDataDirectoryTriggered(); - void onThemeChanged(); - void onThemeChangedFromSettings(); + void updateTheme(); void onLoggingOptionChanged(); void onScreenshotActionTriggered(); void onSaveGSDumpActionTriggered(); @@ -178,10 +180,11 @@ private: NUM_SAVE_STATE_SLOTS = 10, }; + static void setStyleFromSettings(); + static void setIconThemeFromStyle(); + void setupAdditionalUi(); void connectSignals(); - void setStyleFromSettings(); - void setIconThemeFromStyle(); void saveStateToConfig(); void restoreStateFromConfig(); diff --git a/pcsx2-qt/QtHost.cpp b/pcsx2-qt/QtHost.cpp index c40c4dabca..670ef0b088 100644 --- a/pcsx2-qt/QtHost.cpp +++ b/pcsx2-qt/QtHost.cpp @@ -703,8 +703,11 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } - // Start up the CPU thread. + // Set theme before creating any windows. + MainWindow::updateApplicationTheme(); MainWindow* main_window = new MainWindow(QApplication::style()->objectName()); + + // Start up the CPU thread. QtHost::HookSignals(); EmuThread::start();