DolphinQt: Clean up some of the style sheet hacks in StackedSettingsWindow.

This commit is contained in:
Jordan Woyak 2025-09-09 12:22:51 -05:00
commit ecb568c45a

View file

@ -46,46 +46,32 @@ StackedSettingsWindow::StackedSettingsWindow(QWidget* parent) : QDialog{parent}
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. // FYI: "base" is the window color on Windows and "alternate-base" is very high contrast on macOS.
const auto [list_background, list_hover_background] = const auto* const list_background =
#if defined(_WIN32) #if !defined(__APPLE__)
std::pair("palette(alternate-base)", "palette(base)"); "palette(alternate-base)";
#else #else
std::pair("palette(base)", "palette(alternate-base)"); "palette(base)";
#endif #endif
m_navigation_list->setStyleSheet( m_navigation_list->setStyleSheet(
QString::fromUtf8( QString::fromUtf8(
// Remove border around entire widget and adjust background color. // Remove border around entire widget and adjust background color.
"QListWidget { border: 0; background: %1; } " "QListWidget { border: 0; background: %1; } "
"QListWidget::item { padding: %2; " // Note: padding-left is broken unless border is set, which then breaks colors.
#if defined(__linux__) // see: https://bugreports.qt.io/browse/QTBUG-122698
"} " "QListWidget::item { padding-top: %2px; padding-bottom: %2px; } "
#else // Maintain selected item color when unfocused.
// For some reason this is needed to fix inconsistent item padding on Windows and macOS,
// but it unfortunately also breaks item background color changes.
"border: 0; } "
// Restore selected item color.
"QListWidget::item:selected { background: palette(highlight); " "QListWidget::item:selected { background: palette(highlight); "
#if defined(_WIN32) #if !defined(__APPLE__)
// Prevent text color change on focus loss on Windows. // Prevent text color change on focus loss.
// This seems to breaks the nice white text on macOS. // This seems to breaks the nice white text on macOS.
"color: palette(highlighted-text); " "color: palette(highlighted-text); "
#endif #endif
"} " "} "
// Restore hovered item color, though not really the correct color. // Remove ugly dotted outline on selected row (Windows and GNOME).
"QListWidget::item:hover:!selected { background: %3; } " "* { outline: none; } ")
#endif
#if defined(_WIN32)
// Remove ugly dotted outline on selected row.
"* { outline: none; } "
#endif
)
.arg(QString::fromUtf8(list_background)) .arg(QString::fromUtf8(list_background))
.arg(list_item_padding) .arg(list_item_padding));
#if !defined(__linux__)
.arg(QString::fromUtf8(list_hover_background))
#endif
);
layout->addWidget(m_navigation_list); layout->addWidget(m_navigation_list);
@ -120,7 +106,8 @@ void StackedSettingsWindow::OnDoneCreatingPanes()
void StackedSettingsWindow::AddPane(QWidget* widget, const QString& name) void StackedSettingsWindow::AddPane(QWidget* widget, const QString& name)
{ {
m_stacked_panes->addWidget(widget); m_stacked_panes->addWidget(widget);
m_navigation_list->addItem(name); // Pad the left and right of each item.
m_navigation_list->addItem(QStringLiteral(" %1 ").arg(name));
} }
void StackedSettingsWindow::AddWrappedPane(QWidget* widget, const QString& name) void StackedSettingsWindow::AddWrappedPane(QWidget* widget, const QString& name)