From 8c4dee6f97d744ee54d60733f5e160da5e7616c7 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 3 Jan 2022 10:26:19 +0100 Subject: QFusionStyle: don't draw an invalid outline for up/down buttons When they are disabled ('NoButtons'). Otherwise, we end up with a tiny dot (top left or right corner of a spinbox). Pick-to: 6.2 6.3 5.15 Fixes: QTBUG-99486 Change-Id: Ic99f4bce2abd57c988254296a749b5d5b23cfb39 Reviewed-by: Volker Hilsheimer --- src/widgets/styles/qfusionstyle.cpp | 44 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 00a80f565a..43e9c38f07 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -2027,22 +2027,24 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption cachePainter.setPen(d->topShadow()); cachePainter.drawLine(QPoint(r.left() + 2, r.top() + 1), QPoint(r.right() - 2, r.top() + 1)); - // Draw button gradient - QColor buttonColor = d->buttonColor(option->palette); - QRect updownRect = upRect.adjusted(0, -2, 0, downRect.height() + 2); - QLinearGradient gradient = qt_fusion_gradient(updownRect, (isEnabled && option->state & State_MouseOver ) ? buttonColor : buttonColor.darker(104)); + if (!upRect.isNull()) { + // Draw button gradient + const QColor buttonColor = d->buttonColor(option->palette); + const QRect updownRect = upRect.adjusted(0, -2, 0, downRect.height() + 2); + const QLinearGradient gradient = qt_fusion_gradient(updownRect, (isEnabled && option->state & State_MouseOver ) + ? buttonColor : buttonColor.darker(104)); - // Draw button gradient - cachePainter.setPen(Qt::NoPen); - cachePainter.setBrush(gradient); + cachePainter.setPen(Qt::NoPen); + cachePainter.setBrush(gradient); - cachePainter.save(); - cachePainter.setClipRect(updownRect); - cachePainter.drawRoundedRect(r.adjusted(0, 0, -1, -1), 2, 2); - cachePainter.setPen(QPen(d->innerContrastLine())); - cachePainter.setBrush(Qt::NoBrush); - cachePainter.drawRoundedRect(r.adjusted(1, 1, -2, -2), 2, 2); - cachePainter.restore(); + cachePainter.save(); + cachePainter.setClipRect(updownRect); + cachePainter.drawRoundedRect(r.adjusted(0, 0, -1, -1), 2, 2); + cachePainter.setPen(QPen(d->innerContrastLine())); + cachePainter.setBrush(Qt::NoBrush); + cachePainter.drawRoundedRect(r.adjusted(1, 1, -2, -2), 2, 2); + cachePainter.restore(); + } if ((spinBox->stepEnabled & QAbstractSpinBox::StepUpEnabled) && upIsActive) { if (sunken) @@ -2070,12 +2072,14 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption cachePainter.restore(); } - // outline the up/down buttons - cachePainter.setPen(outline); - if (spinBox->direction == Qt::RightToLeft) { - cachePainter.drawLine(upRect.right(), upRect.top() - 1, upRect.right(), downRect.bottom() + 1); - } else { - cachePainter.drawLine(upRect.left(), upRect.top() - 1, upRect.left(), downRect.bottom() + 1); + if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) { + // buttonSymbols == NoButtons results in 'null' rects + // and a tiny rect painted in the corner. + cachePainter.setPen(outline); + if (spinBox->direction == Qt::RightToLeft) + cachePainter.drawLine(upRect.right(), upRect.top() - 1, upRect.right(), downRect.bottom() + 1); + else + cachePainter.drawLine(upRect.left(), upRect.top() - 1, upRect.left(), downRect.bottom() + 1); } if (upIsActive && sunken) { -- cgit v1.2.3