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>
This commit is contained in:
parent
d9bd46b2b8
commit
8ca2d6ba09
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user