diff --git a/src/duckstation-qt/hotkeysettingswidget.cpp b/src/duckstation-qt/hotkeysettingswidget.cpp index 526e3bc2a..f3b59562f 100644 --- a/src/duckstation-qt/hotkeysettingswidget.cpp +++ b/src/duckstation-qt/hotkeysettingswidget.cpp @@ -4,6 +4,7 @@ #include "hotkeysettingswidget.h" #include "controllersettingswindow.h" #include "inputbindingwidgets.h" +#include "mainwindow.h" #include "qtutils.h" #include "settingswindow.h" #include "settingwidgetbinder.h" @@ -23,6 +24,7 @@ HotkeySettingsWidget::HotkeySettingsWidget(QWidget* parent, ControllerSettingsWi : QWidget(parent), m_dialog(dialog) { createUi(); + connect(g_main_window, &MainWindow::themeChanged, this, &HotkeySettingsWidget::onThemeChanged); } HotkeySettingsWidget::~HotkeySettingsWidget() = default; @@ -51,6 +53,24 @@ void HotkeySettingsWidget::Container::repositionSearchBox() m_search->setGeometry(x, box_padding, box_width, h); } +QPalette HotkeySettingsWidget::getLabelPalette(bool is_dark_theme) const +{ + QPalette pal = qApp->palette("QLabel"); + const QColor label_default_color = pal.color(QPalette::Text); + const QColor label_color = is_dark_theme ? label_default_color.darker(120) : label_default_color.lighter(); + pal.setColor(QPalette::Text, label_color); + return pal; +} + +QPalette HotkeySettingsWidget::getRowPalette() const +{ + // This is super jank. The native theme on MacOS does not set AlternateBase like the Windows/Fusion themes do, but + // instead overrides it in QAbstractItemView. + QPalette pal = qApp->palette("QWidget"); + pal.setColor(QPalette::AlternateBase, qApp->palette("QAbstractItemView").color(QPalette::AlternateBase)); + return pal; +} + void HotkeySettingsWidget::createUi() { QGridLayout* layout = new QGridLayout(this); @@ -81,6 +101,8 @@ void HotkeySettingsWidget::createButtons() static constexpr int LR_MARGIN = 8; static constexpr int TB_MARGIN = 4; + const QPalette label_palette = getLabelPalette(QtHost::IsDarkApplicationTheme()); + const QPalette row_palette = getRowPalette(); const std::vector hotkeys(InputManager::GetHotkeyList()); for (const HotkeyInfo* hotkey : hotkeys) { @@ -100,11 +122,6 @@ void HotkeySettingsWidget::createButtons() label_font.setPixelSize(19); label_font.setBold(true); cw.label->setFont(label_font); - QPalette label_palette = cw.label->palette(); - const QColor label_default_color = label_palette.color(QPalette::Text); - const QColor label_color = - QtHost::IsDarkApplicationTheme() ? label_default_color.darker(120) : label_default_color.lighter(); - label_palette.setColor(QPalette::Text, label_color); cw.label->setPalette(label_palette); row_layout->addWidget(cw.label); @@ -124,6 +141,7 @@ void HotkeySettingsWidget::createButtons() QWidget* const row = new QWidget(m_container); row->setAutoFillBackground(true); row->setBackgroundRole((((iter->layout->count()) % 2) == 0) ? QPalette::Base : QPalette::AlternateBase); + row->setPalette(row_palette); iter->layout->addWidget(row); QHBoxLayout* row_layout = new QHBoxLayout(row); @@ -163,3 +181,21 @@ void HotkeySettingsWidget::setFilter(const QString& filter) cw.heading->setVisible(visible_row_count > 0); } } + +void HotkeySettingsWidget::onThemeChanged(bool is_dark_theme) +{ + const QPalette label_palette = getLabelPalette(is_dark_theme); + const QPalette row_palette = getRowPalette(); + for (const CategoryWidgets& cw : m_categories) + { + cw.label->setPalette(label_palette); + cw.line->setPalette(label_palette); + + const int count = cw.layout->count(); + for (int i = 0; i < count; i++) + { + if (QWidget* const row = qobject_cast(cw.layout->itemAt(i)->widget())) + row->setPalette(row_palette); + } + } +} diff --git a/src/duckstation-qt/hotkeysettingswidget.h b/src/duckstation-qt/hotkeysettingswidget.h index 93f7273c1..c2e76f6d1 100644 --- a/src/duckstation-qt/hotkeysettingswidget.h +++ b/src/duckstation-qt/hotkeysettingswidget.h @@ -49,11 +49,16 @@ private: QLineEdit* m_search; }; + QPalette getLabelPalette(bool is_dark_theme) const; + QPalette getRowPalette() const; + void createUi(); void createButtons(); void setFilter(const QString& filter); + void onThemeChanged(bool is_dark_theme); + ControllerSettingsWindow* m_dialog; QScrollArea* m_scroll_area = nullptr; Container* m_container = nullptr; diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 386abdd59..696981bdf 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -2828,6 +2828,7 @@ void MainWindow::changeEvent(QEvent* event) { QtHost::SetIconThemeFromStyle(); reloadThemeSpecificImages(); + emit themeChanged(QtHost::IsDarkApplicationTheme()); } QMainWindow::changeEvent(event); diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 0972b1d94..14a744928 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -140,6 +140,9 @@ public: void onRAIntegrationMenuChanged(); +Q_SIGNALS: + void themeChanged(bool is_dark_theme); + protected: void closeEvent(QCloseEvent* event) override; void changeEvent(QEvent* event) override; diff --git a/src/duckstation-qt/qtthemes.cpp b/src/duckstation-qt/qtthemes.cpp index cef8ce7e1..745d5c487 100644 --- a/src/duckstation-qt/qtthemes.cpp +++ b/src/duckstation-qt/qtthemes.cpp @@ -406,15 +406,6 @@ void QtHost::SetStyleFromSettings() qApp->setPalette(s_state.unthemed_palette); qApp->setStyleSheet(QString()); qApp->styleHints()->setColorScheme(Qt::ColorScheme::Unknown); - -#ifdef __APPLE__ - // This is super jank. The native theme on MacOS does not set AlternateBase like the Windows/Fusion themes do, but - // instead overrides it in QAbstractItemView. Since this is the only place that AlteranteBase is used, just copy it - // across. Why do we need this? Because we're using AlternateBase in hotkey bindings dialog to draw rows manually. - s_state.unthemed_palette.setColor(QPalette::AlternateBase, - qApp->palette("QAbstractItemView").color(QPalette::AlternateBase)); - qApp->setPalette(s_state.unthemed_palette); -#endif } }