From a2f56f7ccf5cd41c9286970280bbf29ff2bc96b0 Mon Sep 17 00:00:00 2001 From: Evgeniy Harchenko Date: Fri, 8 May 2026 08:14:54 +0000 Subject: KItemListWidget: stop overriding style‑provided background brush MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous implementation forced a custom background colour before delegating to the style's PE_PanelItemViewItem primitive. This interferes with theme‑specific drawing and results in a hard‑coded, non‑themed highlight that breaks styling across themes. Remove the explicit brush assignment, allowing the style to paint the background itself. The focus rectangle handling remains unchanged and is still drawn only for the active item. And pass the State_MouseOver to focus rect style option when hovered. --- src/kitemviews/kitemlistwidget.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index b94cf6064..32118c569 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -623,21 +623,6 @@ void KItemListWidget::setPressed(bool enabled) void KItemListWidget::drawItemStyleOption(QPainter *painter, QWidget *widget, QStyle::State styleState) { painter->save(); - // Shared between both Breeze and other styles - QColor backgroundColor{widget->palette().color(QPalette::Highlight)}; - backgroundColor.setAlphaF(0.0); - if (m_clickHighlighted) { - backgroundColor.setAlphaF(1.0); - } else { - if (m_selected && m_hovered) { - backgroundColor.setAlphaF(0.40); - } else if (m_selected) { - backgroundColor.setAlphaF(0.32); - } else if (m_hovered) { - backgroundColor = widget->palette().color(QPalette::Text); - backgroundColor.setAlphaF(0.06); - } - } QStyleOptionViewItem viewItemOption; initStyleOption(&viewItemOption); viewItemOption.state = styleState; @@ -649,6 +634,20 @@ void KItemListWidget::drawItemStyleOption(QPainter *painter, QWidget *widget, QS // TODO: Remove this check after Plasma 6.8 release // See: https://invent.kde.org/plasma/breeze/-/merge_requests/595 if (style()->name() == QStringLiteral("breeze")) { + QColor backgroundColor{widget->palette().color(QPalette::Highlight)}; + backgroundColor.setAlphaF(0.0); + if (m_clickHighlighted) { + backgroundColor.setAlphaF(1.0); + } else { + if (m_selected && m_hovered) { + backgroundColor.setAlphaF(0.40); + } else if (m_selected) { + backgroundColor.setAlphaF(0.32); + } else if (m_hovered) { + backgroundColor = widget->palette().color(QPalette::Text); + backgroundColor.setAlphaF(0.06); + } + } painter->setRenderHint(QPainter::Antialiasing); constexpr int roundness = 5; // From Breeze style. constexpr qreal penWidth = 1.25; @@ -668,7 +667,6 @@ void KItemListWidget::drawItemStyleOption(QPainter *painter, QWidget *widget, QS painter->strokePath(path, pen); } } else { - viewItemOption.backgroundBrush = backgroundColor; style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); // Focus decoration @@ -679,6 +677,9 @@ void KItemListWidget::drawItemStyleOption(QPainter *painter, QWidget *widget, QS if (m_selected && widget->hasFocus()) { focusRectOption.state = QStyle::State_HasFocus | QStyle::State_Selected; } + if (m_hovered) { + focusRectOption.state |= QStyle::State_MouseOver; + } focusRectOption.rect = viewItemOption.rect; style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusRectOption, painter, widget); } -- cgit v1.3