From 6e8ac905397bf3067631c495e568471b4f908f37 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 29 Mar 2018 19:25:40 +0200 Subject: [PATCH] QAbstractSpinBox: honor QAbstractSpinBox::NoButtons in sizeHint() QCommonStyle::sizeFromContents() did not check if a spinbox has buttons or not and returned a to wide width when no buttons are displayed. Task-number: QTBUG-67126 Change-Id: I9f97a31a89a0986023316b02e11017e620c0f614 Reviewed-by: Friedemann Kleint Reviewed-by: Gabriel de Dietrich --- src/widgets/styles/qcommonstyle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index f78aca58ac..8965f913d5 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -4934,8 +4934,8 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, case CT_SpinBox: if (const QStyleOptionSpinBox *vopt = qstyleoption_cast(opt)) { // Add button + frame widths - int buttonWidth = 20; - int fw = vopt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt, widget) : 0; + const int buttonWidth = (vopt->subControls & (QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown)) != 0 ? 20 : 0; + const int fw = vopt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt, widget) : 0; sz += QSize(buttonWidth + 2*fw, 2*fw); } break;