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 <volker.hilsheimer@qt.io>
This commit is contained in:
Timur Pocheptsov 2022-01-03 10:26:19 +01:00
parent c0ca46de3e
commit 8c4dee6f97

View File

@ -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) {