From eab71ff6b0d4bee0b872e5ba38a52f9406df40e2 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 2 Dec 2024 19:07:18 +0100 Subject: [PATCH] Windows11Style: adjust subline color in editable widgets in dark mode The color of the subline in editable widgets was black in light and dark mode. Fix it to use white in dark mode to make it visible. Move it out into own helper function since it's used in at least three places. Pick-to: 6.8 Task-nubmer: QTBUG-131585 Fixes: QTBUG-131586 Change-Id: Icca2b142a1ce0c3d7f722baa6d3635bae5950e1c Reviewed-by: Axel Spoerl (cherry picked from commit 66d42b62b6f01205cf1db72e56ecb5166554e373) Reviewed-by: Qt Cherry-pick Bot --- .../styles/modernwindows/qwindows11style.cpp | 25 ++++++++++--------- .../styles/modernwindows/qwindows11style_p.h | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index e5337ed6a93..5a90c3e4735 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -254,11 +254,8 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt if (cp.needsPainting()) { if (sb->frame && (sub & SC_SpinBoxFrame)) { cp->save(); - QRegion clipRegion = option->rect; - clipRegion -= option->rect.adjusted(2, 2, -2, -2); - cp->setClipRegion(clipRegion); - QColor lineColor = state & State_HasFocus ? option->palette.accent().color() : QColor(0,0,0); - cp->setPen(QPen(lineColor)); + cp->setClipRect(option->rect.adjusted(-2, -2, 2, 2)); + cp->setPen(editSublineColor(option, colorSchemeIndex)); cp->drawLine(option->rect.bottomLeft() + QPointF(7, -0.5), option->rect.bottomRight() + QPointF(-7, -0.5)); cp->restore(); @@ -470,8 +467,7 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt painter->drawText(rect, QStringLiteral(u"\uE70D"), Qt::AlignVCenter | Qt::AlignHCenter); } if (combobox->editable) { - QColor lineColor = state & State_HasFocus ? option->palette.accent().color() : QColor(0,0,0); - painter->setPen(QPen(lineColor)); + painter->setPen(editSublineColor(option, colorSchemeIndex)); painter->drawLine(rect.bottomLeft() + QPoint(2,1), rect.bottomRight() + QPoint(-2,1)); if (state & State_HasFocus) painter->drawLine(rect.bottomLeft() + QPoint(3,2), rect.bottomRight() + QPoint(-3,2)); @@ -969,11 +965,8 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption painter->setBrush(Qt::NoBrush); painter->setPen(highContrastTheme == true ? option->palette.buttonText().color() : QPen(WINUI3Colors[colorSchemeIndex][frameColorLight])); painter->drawRoundedRect(option->rect, secondLevelRoundingRadius, secondLevelRoundingRadius); - QRegion clipRegion = option->rect; - clipRegion -= option->rect.adjusted(2, 2, -2, -2); - painter->setClipRegion(clipRegion); - QColor lineColor = state & State_HasFocus ? option->palette.accent().color() : QColor(0,0,0); - painter->setPen(QPen(lineColor)); + painter->setClipRect(option->rect.adjusted(-2, -2, 2, 2)); + painter->setPen(editSublineColor(option, colorSchemeIndex)); painter->drawLine(option->rect.bottomLeft() + QPointF(1,0.5), option->rect.bottomRight() + QPointF(-1,0.5)); } break; @@ -2348,6 +2341,14 @@ QPen QWindows11Style::buttonLabelPen(const QStyleOption *option, int colorScheme : option->palette.buttonText().color()); } +QColor QWindows11Style::editSublineColor(const QStyleOption *option, int colorSchemeIndex) +{ + const State state = option->state; + return state & State_HasFocus ? option->palette.accent().color() + : (colorSchemeIndex == 0 ? QColor(0x80, 0x80, 0x80) + : QColor(0xa0, 0xa0, 0xa0)); +} + #undef SET_IF_UNRESOLVED QT_END_NAMESPACE diff --git a/src/plugins/styles/modernwindows/qwindows11style_p.h b/src/plugins/styles/modernwindows/qwindows11style_p.h index 05b483ca8cb..35fea6b3a50 100644 --- a/src/plugins/styles/modernwindows/qwindows11style_p.h +++ b/src/plugins/styles/modernwindows/qwindows11style_p.h @@ -55,6 +55,7 @@ protected: private: static inline QBrush buttonFillBrush(const QStyleOption *option); static inline QPen buttonLabelPen(const QStyleOption *option, int colorSchemeIndex); + static inline QColor editSublineColor(const QStyleOption *option, int colorSchemeIndex); private: Q_DISABLE_COPY_MOVE(QWindows11Style)