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