QCommonStyle: draw focus rect using qDrawPlainRect

A non-aliased drawRect(r.adjusted(0, 0, -1, -1)) no longer does the job
in Qt6: hi-dpi is now enabled automatically, which scales the painter
and leads to horrible (non symmetric) rendering.

I doubt any actual widget style calls into this code (which draws
a focus rect with a plain line) but it's still a useful example
and fallback when writing a widget style.

Change-Id: Ib407a7355033258be568b4826fe01c110f02c018
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
(cherry picked from commit 5ef5f2f1b9d90264df02277884e5e18f8c1fc783)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
David Faure 2023-11-28 18:07:44 +01:00 committed by Qt Cherry-pick Bot
parent 5344baee29
commit 0361ff8939

View File

@ -189,20 +189,20 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
case PE_FrameFocusRect:
if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
QColor bg = fropt->backgroundColor;
QPen oldPen = p->pen();
QColor color;
if (bg.isValid()) {
int h, s, v;
bg.getHsv(&h, &s, &v);
if (v >= 128)
p->setPen(Qt::black);
color = Qt::black;
else
p->setPen(Qt::white);
color = Qt::white;
} else {
p->setPen(opt->palette.windowText().color());
color = opt->palette.windowText().color();
}
QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);
p->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive
p->setPen(oldPen);
const QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);
const QBrush fill(bg);
qDrawPlainRect(p, focusRect, color, 1, bg.isValid() ? &fill : nullptr);
}
break;
case PE_IndicatorMenuCheckMark: {