From afce2b528ce30e19af618b077e3f184cf290fa81 Mon Sep 17 00:00:00 2001 From: Caroline Chao Date: Mon, 2 Sep 2013 13:01:32 +0200 Subject: Fix QSpinBox size calculation problem with stylesheets Problem caused by change a317ee0a6fa76d1166f6da8593d39eaf7afce83c Task-number: QTBUG-31602 Change-Id: Ie8948445a58f51946f21d567ba91f9f10b848f8b Reviewed-by: Jens Bache-Wiig --- dist/changes-5.2.0 | 3 +++ src/widgets/styles/qstylesheetstyle.cpp | 30 ++++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/dist/changes-5.2.0 b/dist/changes-5.2.0 index 89d1a2d8c7..5e984a41d8 100644 --- a/dist/changes-5.2.0 +++ b/dist/changes-5.2.0 @@ -37,6 +37,9 @@ QtWidgets - QSizePolicy got a retainSizeWhenHidden attribute. +- [QTBUG-31602] QSpinBox size calculation will now be fixed when stylesheets are + used. + QtCore ------ - [QTBUG-30250] QTime, QDateTime: diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 7b4b882e56..85520d3c40 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -4810,10 +4810,22 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op switch (ct) { case CT_SpinBox: // ### hopelessly broken QAbstractSpinBox (part 1) - if (rule.hasBox() || !rule.hasNativeBorder()) - return csz; - return rule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w) - : QWindowsStyle::sizeFromContents(ct, opt, sz, w); + if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast(opt)) { + // Add some space for the up/down buttons + QRenderRule subRule = renderRule(w, opt, PseudoElement_SpinBoxUpButton); + if (subRule.hasDrawable()) { + QRect r = positionRect(w, rule, subRule, PseudoElement_SpinBoxUpButton, + opt->rect, opt->direction); + sz += QSize(r.width(), 0); + } else { + QSize defaultUpSize = defaultSize(w, subRule.size(), spinbox->rect, PseudoElement_SpinBoxUpButton); + sz += QSize(defaultUpSize.width(), 0); + } + if (rule.hasBox() || !rule.hasNativeBorder()) + sz = rule.boxSize(sz); + return sz; + } + break; case CT_ToolButton: if (rule.hasBox() || !rule.hasNativeBorder() || !rule.baseStyleCanDraw()) sz += QSize(3, 3); // ### broken QToolButton @@ -4858,14 +4870,8 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op case CT_GroupBox: case CT_LineEdit: #ifndef QT_NO_SPINBOX - // ### hopelessly broken QAbstractSpinBox (part 2) - if (QAbstractSpinBox *spinBox = qobject_cast(w ? w->parentWidget() : 0)) { - QRenderRule rule = renderRule(spinBox, opt); - if (rule.hasBox() || !rule.hasNativeBorder()) - return csz; - return rule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w) - : QWindowsStyle::sizeFromContents(ct, opt, sz, w); - } + if (qobject_cast(w ? w->parentWidget() : 0)) + return csz; // we only care about the size hint of the line edit #endif if (rule.hasBox() || !rule.hasNativeBorder()) { return rule.boxSize(sz); -- cgit v1.2.3