From 448329e82166fcd6924c554c781db132f26a170e Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sun, 9 Nov 2025 01:55:52 -0500 Subject: [PATCH] SettingsWindow: Set navigation list stylesheet in constructor --- .../Core/DolphinQt/Config/SettingsWindow.cpp | 51 ++++++++++--------- Source/Core/DolphinQt/Config/SettingsWindow.h | 1 - 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Source/Core/DolphinQt/Config/SettingsWindow.cpp b/Source/Core/DolphinQt/Config/SettingsWindow.cpp index 04b1f2d0210..947edb39181 100644 --- a/Source/Core/DolphinQt/Config/SettingsWindow.cpp +++ b/Source/Core/DolphinQt/Config/SettingsWindow.cpp @@ -39,7 +39,7 @@ StackedSettingsWindow::StackedSettingsWindow(QWidget* parent) : QDialog{parent} auto* const layout = new QHBoxLayout{this}; // Calculated value for the padding in our list items. - m_list_item_padding = layout->contentsMargins().left() / 2; + const int list_item_padding = layout->contentsMargins().left() / 2; // Eliminate padding around layouts. layout->setContentsMargins(QMargins{}); @@ -51,6 +51,31 @@ StackedSettingsWindow::StackedSettingsWindow(QWidget* parent) : QDialog{parent} m_navigation_list->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); m_navigation_list->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); + // FYI: "base" is the window color on Windows and "alternate-base" is very high contrast on macOS. + const auto* const list_background = +#if !defined(__APPLE__) + "palette(alternate-base)"; +#else + "palette(base)"; +#endif + + m_navigation_list->setStyleSheet( + QString::fromUtf8( + // Remove border around entire widget and adjust background color. + "QListWidget { border: 0; background: %1; } " + // Note: padding-left is broken unless border is set, which then breaks colors. + // see: https://bugreports.qt.io/browse/QTBUG-122698 + "QListWidget::item { padding-top: %2px; padding-bottom: %2px; } " + // Maintain selected item color when unfocused. + "QListWidget::item:selected { background: palette(highlight); " + // Prevent text color change on focus loss. + "color: palette(highlighted-text); " + "} " + // Remove ugly dotted outline on selected row (Windows and GNOME). + "* { outline: none; } ") + .arg(QString::fromUtf8(list_background)) + .arg(list_item_padding)); + UpdateNavigationListStyle(); layout->addWidget(m_navigation_list); @@ -115,30 +140,6 @@ void StackedSettingsWindow::UpdateNavigationListStyle() if (!m_navigation_list) return; - // FYI: "base" is the window color on Windows and "alternate-base" is very high contrast on macOS. - const auto* const list_background = -#if !defined(__APPLE__) - "palette(alternate-base)"; -#else - "palette(base)"; -#endif - - m_navigation_list->setStyleSheet( - QString::fromUtf8( - // Remove border around entire widget and adjust background color. - "QListWidget { border: 0; background: %1; } " - // Note: padding-left is broken unless border is set, which then breaks colors. - // see: https://bugreports.qt.io/browse/QTBUG-122698 - "QListWidget::item { padding-top: %2px; padding-bottom: %2px; } " - // Maintain selected item color when unfocused. - "QListWidget::item:selected { background: palette(highlight); " - // Prevent text color change on focus loss. - "color: palette(highlighted-text); " - "} " - // Remove ugly dotted outline on selected row (Windows and GNOME). - "* { outline: none; } ") - .arg(QString::fromUtf8(list_background)) - .arg(m_list_item_padding)); QPalette list_palette = m_navigation_list->palette(); const QPalette app_palette = qApp->palette(); diff --git a/Source/Core/DolphinQt/Config/SettingsWindow.h b/Source/Core/DolphinQt/Config/SettingsWindow.h index 3fd646e7862..9048e833853 100644 --- a/Source/Core/DolphinQt/Config/SettingsWindow.h +++ b/Source/Core/DolphinQt/Config/SettingsWindow.h @@ -35,7 +35,6 @@ private: QStackedWidget* m_stacked_panes = nullptr; QListWidget* m_navigation_list = nullptr; - int m_list_item_padding = 0; bool m_handling_theme_change = false; };