[Qt-interest] How to Reach All The Points of a QPainterPath

Samuel Rødal samuel.rodal at nokia.com
Wed Apr 7 14:15:08 CEST 2010


ext hakiim the dream wrote:
> Hello again,
> 
> In fact, I expect  x and y coordinates of path elements of the path 
> handles my problem, too. But, they cannot, or I miss something.
> 
> 
> My real problem:
> 
>     QPainterPath *path = new QPainterPath();
> 
>     path->addEllipse(QRectF(*rect));
> 
> 
> Then, I must get the points of this ellipse into
> 
>     QList<QPointF>* pathPoints
> 
> 
> But, using
> 
>       QPointF pathPoint;
> 
>       int count = path->elementCount();
> 
>       for(int i=0; i<count; i++)
> 
>       {
> 
>             pathPoint.setX(path->elementAt(i).x);
> 
>             pathPoint.setY(path->elementAt(i).y);
> 
>             pathPoints->append(pathPoint);
> 
>       }
> 
>  
> 
> I see the ellipse has 13 elements, it means it gives me just 13 points. 
> But I must draw the same ellipse using these points and
> 
> Void PainterPath::lineTo(qreal x, qreal y).
> 
> 
> Thanks.

This is because a QPainterPath contains not only line segments but also 
bezier curves. If you want to flatten the curves into line segments you 
can use QPainterPath::toFillPolygon() which returns a QPolygonF which is 
also a QVector of QPointF.

--
Samuel



More information about the Qt-interest-old mailing list