Qt-interest Archive, August 2006
Problem with drawing arc
Message 1 in thread
Hi
I need to be able to draw an arc inside of two concentic circles. The
circles are spaced 10 pixels apart. My first attempt was to use drawArc from
QPainter, with a thick pen i.e. the pen width = 10. The problem was that
when the widget is resized the pen width stays the same i.e. it doesn't
scale along with the circles. My next attempt involved QPointArray::makeArc
to make two arcs of the appropriate width, with a line joining the start
points and end points. The problem with this method is the thick arc does
not get filled with the set brush color. My last attempt involved
QPointArray::makeArc. First I called QPointArray::copy to make a copy of the
inner arc. Then I resized the array by 1 and set the next point to the end
point of the outer arc. I copy the outer arc points into the temp array in
reverse order. Finally, the two arc form an enclosed shape by joining the
two start points together. Again this method does not work. Can anybody
suggest a method for drawing a thick arc, which scales when resized?
Regards
John Dean
Message 2 in thread
John Dean wrote:
> Can anybody suggest a method for drawing a thick arc, which
> scales when resized?
You could create the arc using QPainterPath then use QPainterPathStroker to
create a new path based on the outline of the original one. Paint it with a
brush rather than a pen to get an opaque arc.
--
[ signature omitted ]
Message 3 in thread
On 25/08/06, David Boddie <dboddie@xxxxxxxxxxxxx> wrote:
>
> John Dean wrote:
>
> > Can anybody suggest a method for drawing a thick arc, which
> > scales when resized?
>
> You could create the arc using QPainterPath then use QPainterPathStroker
> to
> create a new path based on the outline of the original one. Paint it with
> a
> brush rather than a pen to get an opaque arc.
Unfortunately, I have to work with Qt V3.3.x. What you have suggested would
what I would have done had been working with QtV4.x.x. I have tried without
success to get the management to upgrade to Qt 4.x.x but they have it in
their collective heads that QtV4.x.x is immature and unstable.
Thank you anyway for your suggest
BTW I have come with a solution using small filled rectangles and matrix
tranformations i.e. rotate and translate
--
[ signature omitted ]
Message 4 in thread
John Dean wrote:
> Unfortunately, I have to work with Qt V3.3.x. What you have suggested
> would what I would have done had been working with QtV4.x.x. I have tried
> without success to get the management to upgrade to Qt 4.x.x but they have
> it in their collective heads that QtV4.x.x is immature and unstable.
That's a shame. :-(
> BTW I have come with a solution using small filled rectangles and matrix
> tranformations i.e. rotate and translate
You could construct two empty point arrays and create arcs with the
makeArc() function that run in opposite directions. You then construct
another point array that's large enough to hold all the points from the
other two, then copy all those points into it.
The following code is untested, but it should give you an idea of what
you could do:
QPointArray firstArc; // outer counter-clockwise arc
firstArc.makeArc(0, 0, 100, 100, 0, 16*60); // from 0 to 60 degrees
QPointArray secondArc; // inner clockwise arc
secondArc.makeArc(10, 10, 80, 80, 16*60, -16*60); // from 60 to 0 degrees
QPointArray bothArcs(firstArc.size() + secondArc.size());
for (int i = 0; i < firstArc.size(); ++i)
bothArcs.setPoint(i, firstArc.point(i));
for (int j = 0; j < secondArc.size(); ++j)
bothArcs.setPoint(i + j, secondArc.point(j));
Finally, you set a suitable brush on the QPainter and call drawPolygon()
to draw the whole shape:
QPainter painter;
painter.begin(this);
painter.setBrush(QBrush(Qt::red));
painter.drawPolygon(bothArcs);
painter.end();
Good luck!
--
[ signature omitted ]