QCommonStyle: sync CT_SpinBox with subControlRect()

The size calculation for CT_SpinBox was out-of-sync with the rects
calculated in subControlRect() for SC_SpinBoxUp/Down.

Fixes: QTBUG-115451
Change-Id: I140346fa1980e0cf95e0a07499f43467b721f01e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 60c665d0b320324affa76702b5e5de3d37117809)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2024-11-07 18:33:57 +01:00 committed by Qt Cherry-pick Bot
parent 9493166694
commit 03ea1ebbe5

View File

@ -5050,14 +5050,16 @@ QSize QCommonStyle::sizeFromContents(ContentsType contentsType, const QStyleOpti
#if QT_CONFIG(spinbox)
case CT_SpinBox:
if (const auto *spinBoxOpt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
// Add button + frame widths
const qreal dpi = QStyleHelper::dpi(opt);
const int frameWidth = spinBoxOpt->frame
? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinBoxOpt, widget)
: 0;
size += QSize(2 * frameWidth, 2 * frameWidth);
const bool hasButtons = (spinBoxOpt->buttonSymbols != QAbstractSpinBox::NoButtons);
const int buttonWidth = hasButtons ? qRound(QStyleHelper::dpiScaled(16, dpi)) : 0;
const int frameWidth = spinBoxOpt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth,
spinBoxOpt, widget) : 0;
size += QSize(buttonWidth + 2 * frameWidth, 2 * frameWidth);
if (hasButtons) {
const auto height = qMax(8, size.height() / 2 - frameWidth);
const auto buttonWidth = qMax(16, qMin(height * 8 / 5, size.width() / 3));
size.rwidth() += buttonWidth;
}
}
break;
#endif