Qt: Work around theme switching issue in 6.4.0

Starting in dark theme then switching to native/light would not restore
the standard palette.
This commit is contained in:
Connor McLaughlin 2022-11-20 14:26:23 +10:00 committed by refractionpcsx2
parent f79b57d0cf
commit 0dd766cec8
3 changed files with 8 additions and 9 deletions

View File

@ -93,6 +93,7 @@ const char* MainWindow::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__)
@ -109,8 +110,7 @@ static bool s_use_central_widget = false;
static bool s_vm_valid = false;
static bool s_vm_paused = false;
MainWindow::MainWindow(const QString& unthemed_style_name)
: m_unthemed_style_name(unthemed_style_name)
MainWindow::MainWindow()
{
pxAssert(!g_main_window);
g_main_window = this;
@ -439,7 +439,7 @@ void MainWindow::recreate()
close();
g_main_window = nullptr;
MainWindow* new_main_window = new MainWindow(m_unthemed_style_name);
MainWindow* new_main_window = new MainWindow();
new_main_window->initialize();
new_main_window->refreshGameList(false);
new_main_window->show();
@ -486,6 +486,7 @@ void MainWindow::updateApplicationTheme()
{
s_unthemed_style_name_set = true;
s_unthemed_style_name = QApplication::style()->objectName();
s_unthemed_palette = QApplication::style()->standardPalette();
}
setStyleFromSettings();
@ -498,7 +499,7 @@ void MainWindow::setStyleFromSettings()
if (theme == "fusion")
{
qApp->setPalette(QApplication::style()->standardPalette());
qApp->setPalette(s_unthemed_palette);
qApp->setStyleSheet(QString());
qApp->setStyle(QStyleFactory::create("Fusion"));
}
@ -770,7 +771,7 @@ void MainWindow::setStyleFromSettings()
}
else
{
qApp->setPalette(QApplication::style()->standardPalette());
qApp->setPalette(s_unthemed_palette);
qApp->setStyleSheet(QString());
qApp->setStyle(s_unthemed_style_name);
}

View File

@ -78,7 +78,7 @@ public:
static const char* DEFAULT_THEME_NAME;
public:
explicit MainWindow(const QString& unthemed_style_name);
MainWindow();
~MainWindow();
/// Sets application theme according to settings.
@ -243,8 +243,6 @@ private:
Ui::MainWindow m_ui;
QString m_unthemed_style_name;
GameListWidget* m_game_list_widget = nullptr;
DisplayWidget* m_display_widget = nullptr;
DisplayContainer* m_display_container = nullptr;

View File

@ -1833,7 +1833,7 @@ int main(int argc, char* argv[])
// Set theme before creating any windows.
MainWindow::updateApplicationTheme();
MainWindow* main_window = new MainWindow(QApplication::style()->objectName());
MainWindow* main_window = new MainWindow();
// Start up the CPU thread.
QtHost::HookSignals();