summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-04-21 13:09:07 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-05-10 19:52:11 +0200
commitaa8d3f90a440575deef914916299b792105d7209 (patch)
tree6aa6c43a453f99e133af326fe6ceab43ad1aad6d /src/widgets/styles
parent12ebdf0281b341726a01c41bac8e8a960f4b07ce (diff)
QAbstractSpinBox: fix some ui glitches
Fix some ui glitches for QAbstractSpinBox: - update geometry when buttons are toggled on/off - calc button size with subControlRect instead hardcoded 20px - when buttons are not shown, don't add the button size in sizeFromContents for common and macOS style Fixes: QTBUG-39713 Fixes: QTBUG-75303 Task-number: QTBUG-67126 Change-Id: Ibf330c76deb16358a481bba6bd429fff6a5d57ae Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp3
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp30
2 files changed, 20 insertions, 13 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index a3461d8848..35b630cde2 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -5029,7 +5029,8 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
case CT_SpinBox:
if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
// Add button + frame widths
- const int buttonWidth = (vopt->subControls & (QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown)) != 0 ? 20 : 0;
+ const bool hasButtons = (vopt->buttonSymbols != QAbstractSpinBox::NoButtons);
+ const int buttonWidth = hasButtons ? proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp, widget).width() : 0;
const int fw = vopt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt, widget) : 0;
sz += QSize(buttonWidth + 2*fw, 2*fw);
}
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 2118bad9d6..84299263d7 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -4987,17 +4987,19 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
switch (ct) {
#if QT_CONFIG(spinbox)
- case CT_SpinBox: // ### hopelessly broken QAbstractSpinBox (part 1)
+ case CT_SpinBox:
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 (spinbox->buttonSymbols != QAbstractSpinBox::NoButtons) {
+ // 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.rwidth() += r.width();
+ } else {
+ QSize defaultUpSize = defaultSize(w, subRule.size(), spinbox->rect, PseudoElement_SpinBoxUpButton);
+ sz.rwidth() += defaultUpSize.width();
+ }
}
if (rule.hasBox() || rule.hasBorder() || !rule.hasNativeBorder())
sz = rule.boxSize(sz);
@@ -5498,8 +5500,12 @@ QRect QStyleSheetStyle::subControlRect(ComplexControl cc, const QStyleOptionComp
: Qt::Alignment(Qt::AlignRight);
downAlign = resolveAlignment(opt->direction, downAlign);
- int upSize = subControlRect(CC_SpinBox, opt, SC_SpinBoxUp, w).width();
- int downSize = subControlRect(CC_SpinBox, opt, SC_SpinBoxDown, w).width();
+ const bool hasButtons = (spin->buttonSymbols != QAbstractSpinBox::NoButtons);
+ const int upSize = hasButtons
+ ? subControlRect(CC_SpinBox, opt, SC_SpinBoxUp, w).width() : 0;
+ const int downSize = hasButtons
+ ? subControlRect(CC_SpinBox, opt, SC_SpinBoxDown, w).width() : 0;
+
int widestL = qMax((upAlign & Qt::AlignLeft) ? upSize : 0,
(downAlign & Qt::AlignLeft) ? downSize : 0);
int widestR = qMax((upAlign & Qt::AlignRight) ? upSize : 0,