summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-04-14 16:13:06 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-04-15 13:56:27 +0200
commit8ca2d6ba09c4fad8a8d8adf97681c61d53c3a8b4 (patch)
tree85dbf46091e7bb1eecbc467aa5e4654a7ee5aa78 /src/widgets
parentd9bd46b2b833ce7cf026e1cd462885bde22f5552 (diff)
CommonStyle/QSpinBox: fix rendering up/down symbols in high-dpi mode
The previous patch for QTBUG-112019 could lead to an uneven length which in results in an incorrect center. Fix it by making sure that the length (and width) of the two rectangles are even so we always get a proper center without fiddling around with float values. Also honor PM_ButtonShiftHorizontal/Vertical now (was forgotten in the last patch). Pick-to: 6.5 Fixes: QTBUG-112019 Fixes: QTBUG-112861 Change-Id: Ifc19b863c761ae545208b996ba60d1f33bceb2b3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index 28731aaca1..5736538443 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -501,23 +501,22 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
h = qRound(devicePixelRatio * h);
p->translate(0.5, 0.5);
}
- // center and make sure horizontal and vertical line has equal length
- if (w < h) {
- y += (h - w) / 2;
- h = w;
- } else {
- x += (w - h) / 2;
- w = h;
- }
-
- int offset = (opt->state & State_Sunken) ? 1 : 0;
- int step = (w + 4) / 5;
- p->fillRect(x + offset, y + offset + h / 2 - step / 2, w, step,
- opt->palette.buttonText());
- if (pe == PE_IndicatorSpinPlus) {
- p->fillRect(x + w / 2 - step / 2 + offset, y + offset, step, h,
- opt->palette.buttonText());
+ int len = std::min(w, h);
+ if (len & 1)
+ ++len;
+ int step = (len + 4) / 5;
+ if (step & 1)
+ ++step;
+ const int step2 = step / 2;
+ QPoint center(x + w / 2, y + h / 2);
+ if (opt->state & State_Sunken) {
+ center += QPoint(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt),
+ proxy()->pixelMetric(PM_ButtonShiftVertical, opt));
}
+ p->translate(center);
+ p->fillRect(-len / 2, -step2, len, step, opt->palette.buttonText());
+ if (pe == PE_IndicatorSpinPlus)
+ p->fillRect(-step2, -len / 2, step, len, opt->palette.buttonText());
p->restore();
break; }
case PE_IndicatorSpinUp: