Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get a list with QPoints from QPainter?



  • Hello,

    I would like to draw Ellipse using QPainter. Now I would like to get all QPoints, which were drawn by this function. Of course that can be QVector, QList or something else.

    I know that I can use mathematical formula, but maybe is there any simple way to achieve, what I want?

    EDIT: I find a solution, but I think it's not perfect.

    Now I draw Ellipse using QPainterPath and arcTo() with tle last param = 360. Next for each QPoint in QRect of this ellipse I check using intersects.

    My code:

        painterPath.moveTo(80,50);
        
        painterPath.arcTo(20.0, 30.0, 60.0, 40.0, 0.0, 360.0);
    
        painter.drawPath(painterPath);
    
        for(int i=20;i<80;i++)
        {
            for(int j=30;j<70;j++)
            {
                qInfo()<<i<<j<<painterPath.intersects(QRect(i,j,1,1));
            }
        }
    


  • @TomNow99 Hi, I guess you can use QPainterPath::toFillPolygons() to get a list of QPolygonF representing your shape, and QPolygonF inherits from QVector<QPointF> so you can probably iterate on this to get all your points.

    Something like this : (not tested)

    const auto polygons = painterPath.toFillPolygons();
    for (const auto &polygon in polygons){
        for(const auto &point in polygon) {
            qInfo << point;
        }
    }
    


  • @Gojir4

    Thank you. I check your code, but I get only this:

    s.png

    ( I change qInfo() to painter.drawPoint() )



  • @TomNow99 said in How to get a list with QPoints from QPainter?:

    hank you. I check your code, but I get only this:

    I thought this was what you wanted. What is missing ?



  • @Gojir4 I would like to get all points from circle border.



  • @TomNow99 That's all the points. the painter will trace lines between these points to draw the ellipsis. If you really want all the points on the circle I guess you will need to calculate this by yourself. So your first solution is probably already correct. But I'm far to be an expert of QPainter so there's probably a better solution IDK.


Log in to reply