From 0ca3f1732ae9aa8e138142890a35c0b183c55ffd Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 22 Dec 2020 15:43:13 +0100 Subject: QDial: fix painting QDial when the rect has an offset When the QDial should be painted with an offset, the dial was not draw correct. Fixes: QTBUG-89574 Change-Id: I646c3d42fba34e8c603a8f81f363ed827f04d5de Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qcommonstyle.cpp | 4 ++-- src/widgets/styles/qstylehelper.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 3bdababe2c..ff115596bf 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -3230,8 +3230,8 @@ static StaticPolygonF<3> calcArrow(const QStyleOptionSlider *dial, qreal &a) a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI / (dial->maximum - dial->minimum)) / 6; - int xc = width / 2; - int yc = height / 2; + int xc = width / 2 + dial->rect.left(); + int yc = height / 2 + dial->rect.top(); int len = r - QStyleHelper::calcBigLineSize(r) - 5; if (len < 5) diff --git a/src/widgets/styles/qstylehelper.cpp b/src/widgets/styles/qstylehelper.cpp index d8e0495b37..377df7705b 100644 --- a/src/widgets/styles/qstylehelper.cpp +++ b/src/widgets/styles/qstylehelper.cpp @@ -181,7 +181,7 @@ static QPointF calcRadialPos(const QStyleOptionSlider *dial, qreal offset) qreal len = r - QStyleHelper::calcBigLineSize(r) - 3; qreal back = offset * len; QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a))); - return pos; + return pos + dial->rect.topLeft(); } qreal angle(const QPointF &p1, const QPointF &p2) @@ -254,7 +254,7 @@ QPolygonF calcLines(const QStyleOptionSlider *dial) poly[2 * i + 1] = QPointF(xc + (r - 1) * c, yc -(r - 1) * s); } } - return poly; + return poly.translated(dial->rect.topLeft()); } // This will draw a nice and shiny QDial for us. We don't want @@ -291,8 +291,8 @@ void drawDial(const QStyleOptionSlider *option, QPainter *painter) p->setRenderHint(QPainter::Antialiasing); const qreal d_ = r / 6; - const qreal dx = option->rect.x() + d_ + (width - 2 * r) / 2 + 1; - const qreal dy = option->rect.y() + d_ + (height - 2 * r) / 2 + 1; + const qreal dx = d_ + (width - 2 * r) / 2 + 1; + const qreal dy = d_ + (height - 2 * r) / 2 + 1; QRectF br = QRectF(dx + 0.5, dy + 0.5, int(r * 2 - 2 * d_ - 2), -- cgit v1.2.3