summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles/qcommonstyle.cpp
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2023-11-28 18:07:44 +0100
committerDavid Faure <david.faure@kdab.com>2023-11-29 08:58:46 +0100
commit5ef5f2f1b9d90264df02277884e5e18f8c1fc783 (patch)
treebc5d164016e494d638cc762b123ba479b05e8a6e /src/widgets/styles/qcommonstyle.cpp
parent7a3fed3f209e5113434647897c4f16a7ac3d9c01 (diff)
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. Pick-to: 6.6 Change-Id: Ib407a7355033258be568b4826fe01c110f02c018 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Diffstat (limited to 'src/widgets/styles/qcommonstyle.cpp')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index 730e9fef1f..54c07c1cbe 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -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: {