2
votes

The image below shows the grey pie, I would like to draw this using Qt 5.5

X increases left to right Y increases top to bottom

I have a start angle and an end angle which represents to the top and bottom of the arc, I am calculating the arc angle using:

double dblArcAngle = fmod(mcfltElevMaxLimit - mcfltElevMinLimit + 180.0, 360.0) - 180.0;

Where:

mcfltElevMaxLimit is 60 and mcfltElevMinLimit is -10

The call to drawPie looks like this:

objOffscrPainter.drawPie(QRect(rctGeom.left() + mcintElevLeftMargin
                               ,rctGeom.top() + mcintElevBottomMargin
                               ,rctGeom.width() - mcintElevLeftMargin
                               ,rctGeom.height() - mcintElevBottomMargin)
                               ,mcfltElevMaxLimit * 16, dblArcAngle * 16);

What I get is a very small polyline about midway up where the pie should be.

(edit), just read in the documentation that both startAngle and spanAngle parameters 2 and 3 should be multiplied by 16, which does produce a pie, not in the correct orientation and not filled to the center but its progress.

(edit 2), more progress, the image below now shows the results I'm getting, the rectangle I'm passing is the outer rectangle and includes the axis, yet for some reason the pie is offset???

enter image description here

What I want to accomplish is the pie tucked into the bottom left aligned with the white axis and filling the image.

It looks like the passed rectangle is used to determine the center point for the pie. If this is correct then the center of the rectangle must be adjusted to be the origin (bottom left) and the size also adjusted to fill the display.

1

1 Answers

1
votes

The rectangle in a first parameter of QPainter::drawPie is a bounding box of a circle which contains your arc. So, to draw what you need try something like this:

objOffscrPainter.drawPie(QRect(center.x() - r, center.y() - r, 2 * r, 2 * r)
    ,16*mcfltElevMaxLimit, 16*dblArcAngle);

(where center is a center of your arc)

It seems that in your case center is a QPoint(0, 0), so you can use this code:

objOffscrPainter.drawPie(-r, -r, 2*r, 2*r, 16*mcfltElevMaxLimit, 16*dblArcAngle);

(we can call it without QRect too, see the documentation)