SettingsWindow: Set navigation list stylesheet in constructor

This commit is contained in:
OatmealDome 2025-11-09 01:55:52 -05:00
parent 5af9bd5e46
commit 448329e821
No known key found for this signature in database
GPG Key ID: A4BFAB0C67513B91
2 changed files with 26 additions and 26 deletions

View File

@ -39,7 +39,7 @@ StackedSettingsWindow::StackedSettingsWindow(QWidget* parent) : QDialog{parent}
auto* const layout = new QHBoxLayout{this}; auto* const layout = new QHBoxLayout{this};
// Calculated value for the padding in our list items. // 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. // Eliminate padding around layouts.
layout->setContentsMargins(QMargins{}); layout->setContentsMargins(QMargins{});
@ -51,6 +51,31 @@ StackedSettingsWindow::StackedSettingsWindow(QWidget* parent) : QDialog{parent}
m_navigation_list->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); m_navigation_list->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
m_navigation_list->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); 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(); UpdateNavigationListStyle();
layout->addWidget(m_navigation_list); layout->addWidget(m_navigation_list);
@ -115,30 +140,6 @@ void StackedSettingsWindow::UpdateNavigationListStyle()
if (!m_navigation_list) if (!m_navigation_list)
return; 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(); QPalette list_palette = m_navigation_list->palette();
const QPalette app_palette = qApp->palette(); const QPalette app_palette = qApp->palette();

View File

@ -35,7 +35,6 @@ private:
QStackedWidget* m_stacked_panes = nullptr; QStackedWidget* m_stacked_panes = nullptr;
QListWidget* m_navigation_list = nullptr; QListWidget* m_navigation_list = nullptr;
int m_list_item_padding = 0;
bool m_handling_theme_change = false; bool m_handling_theme_change = false;
}; };