From 3b42b81bc8c7af109aad135f51cc4377a8acd14a Mon Sep 17 00:00:00 2001
From: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Date: Tue, 21 Jan 2014 18:17:44 +0100
Subject: [PATCH] Fix implicit width for SpinBox

This patch ensures that we take the minimum width of the SpinBox
into account when getting the size from the style item.

The patch still relies on the height of the TextField since we
want to ensure that they keep similar height and the existing
spinbox code behaves somewhat erratic.

Task-number: QTBUG-36283
Change-Id: I50d14e5afb2576548c381e7f70063dfcb727e7d6
[ChangeLog][QtQuickControls]Fixed implicit width for SpinBox
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
---
 src/controls/Private/qquickstyleitem.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/controls/Private/qquickstyleitem.cpp b/src/controls/Private/qquickstyleitem.cpp
index c290bc28e..d45f4e7b0 100644
--- a/src/controls/Private/qquickstyleitem.cpp
+++ b/src/controls/Private/qquickstyleitem.cpp
@@ -601,6 +601,7 @@ void QQuickStyleItem::initStyleOption()
 
         QStyleOptionSpinBox *opt = qstyleoption_cast<QStyleOptionSpinBox*>(m_styleoption);
         opt->frame = true;
+        opt->subControls = QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField;
         if (value() & 0x1)
             opt->activeSubControls = QStyle::SC_SpinBoxUp;
         else if (value() & (1<<1))
@@ -919,6 +920,9 @@ QSize QQuickStyleItem::sizeFromContents(int width, int height)
             frame.rect = m_styleoption->rect;
             frame.styleObject = this;
             size = qApp->style()->sizeFromContents(QStyle::CT_LineEdit, &frame, QSize(width, height));
+            if (m_itemType == SpinBox)
+                size.setWidth(qApp->style()->sizeFromContents(QStyle::CT_SpinBox,
+                                                              m_styleoption, QSize(width + 2, height)).width());
         }
         break;
     case GroupBox: {
-- 
GitLab