QWindows11Style: Use Highlight color for ItemView with alternating rows

When using alternating rows in ItemViews, the currently selected item is
hard to distinguish from the background colors. This patch uses for
ItemViews with alternating row colors the highlight color for the
selected and hovered item.

Fixes: QTBUG-133118
Pick-to: 6.9 6.8
Change-Id: Ib5dbe0f58d5970c41cc9d14cf2188a7e5b1abd1a
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
Wladimir Leuschner 2025-02-10 11:18:40 +01:00
parent c08ca6ff02
commit c3d2a4972c

View File

@ -1032,7 +1032,8 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption
isLast = !isLast;
}
painter->setBrush(WINUI3Colors[colorSchemeIndex][subtleHighlightColor]);
const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget);
painter->setBrush(view->alternatingRowColors() ? vopt->palette.highlight() : WINUI3Colors[colorSchemeIndex][subtleHighlightColor]);
painter->setPen(Qt::NoPen);
if (isFirst) {
painter->save();
@ -1718,7 +1719,8 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
}
if (vopt->state.testAnyFlags(State_Selected | State_MouseOver)) {
painter->setBrush(WINUI3Colors[colorSchemeIndex][subtleHighlightColor]);
const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget);
painter->setBrush(view->alternatingRowColors() ? vopt->palette.highlight() : WINUI3Colors[colorSchemeIndex][subtleHighlightColor]);
QWidget *editorWidget = view ? view->indexWidget(view->currentIndex()) : nullptr;
if (editorWidget) {
QPalette pal = editorWidget->palette();