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.9 6.8
Task-nubmer: QTBUG-131585
Fixes: QTBUG-131586
Change-Id: Icca2b142a1ce0c3d7f722baa6d3635bae5950e1c
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Christian Ehrlicher 2024-12-02 19:07:18 +01:00
parent d5cef74d8d
commit 66d42b62b6
2 changed files with 14 additions and 12 deletions

View File

@ -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

View File

@ -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)