Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get a list with QPoints from QPainter?

How to get a list with QPoints from QPainter?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by TomNow99
    #1

    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));
            }
        }
    
    Gojir4G 1 Reply Last reply
    0
    • T TomNow99

      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));
              }
          }
      
      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @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;
          }
      }
      
      1 Reply Last reply
      0
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by
        #3

        @Gojir4

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

        s.png

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

        Gojir4G 1 Reply Last reply
        0
        • T TomNow99

          @Gojir4

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

          s.png

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

          Gojir4G Offline
          Gojir4G Offline
          Gojir4
          wrote on last edited by
          #4

          @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 ?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            TomNow99
            wrote on last edited by
            #5

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

            Gojir4G 1 Reply Last reply
            0
            • T TomNow99

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

              Gojir4G Offline
              Gojir4G Offline
              Gojir4
              wrote on last edited by
              #6

              @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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved