summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dist/changes-5.2.03
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp30
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<const QStyleOptionSpinBox *>(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<QAbstractSpinBox *>(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<QAbstractSpinBox *>(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);