From 03ea1ebbe538688ec7ce16815bbb8c61df6d56a6 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 7 Nov 2024 18:33:57 +0100 Subject: [PATCH] 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 (cherry picked from commit 60c665d0b320324affa76702b5e5de3d37117809) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qcommonstyle.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index dc812fc15c8..2ea43027fb5 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -5050,14 +5050,16 @@ QSize QCommonStyle::sizeFromContents(ContentsType contentsType, const QStyleOpti #if QT_CONFIG(spinbox) case CT_SpinBox: if (const auto *spinBoxOpt = qstyleoption_cast(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