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. Check if a QPoint lies within a QPolygon
Forum Updated to NodeBB v4.3 + New Features

Check if a QPoint lies within a QPolygon

Scheduled Pinned Locked Moved Solved General and Desktop
qpolygonqpointmousepresseven
5 Posts 2 Posters 1.7k Views
  • 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.
  • H Offline
    H Offline
    hobbyProgrammer
    wrote on last edited by
    #1

    I would like to check if a QPoint lies withing a QPolygon (so not just that QPolygon contains a point QPoint, since those are only for the outside). I would really like to check if it's within the surface of a QPolygon.
    I'd like to check on a right mouse press event.

    JonBJ 1 Reply Last reply
    0
    • H hobbyProgrammer

      @JonB I save my qpolygon's in a qvector. When I try qv_polygons.at(i).contains it doesn't seem to work properly, but I also don't get the oppertunity to use containsPoint.

      I get the error:

      const class QVecor<QPoint> had no member named containsPoint;
      

      with outside I mean on the edge/corner points that are stored within QPolygon.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #4

      @hobbyProgrammer
      What's a QVecor[sic.]?
      Check what your qv_polygons.at(i) actually is, because the error message tells you it thinks it's a QVecor<QPoint>, not a QPolygon. Ah, I see

      A QPolygon object is a QVector<QPoint>.

      You may need something like a <static_cast>(QPolygon)? Or possibly QPolygon(const QVector<QPoint> &points) to get a (new) QPolygon out of the points vector, I don't know.

      H 1 Reply Last reply
      1
      • H hobbyProgrammer

        I would like to check if a QPoint lies withing a QPolygon (so not just that QPolygon contains a point QPoint, since those are only for the outside). I would really like to check if it's within the surface of a QPolygon.
        I'd like to check on a right mouse press event.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @hobbyProgrammer

        (so not just that QPolygon contains a point QPoint, since those are only for the outside)

        What "outside"? https://doc.qt.io/qt-5/qpolygon.html#containsPoint

        Returns true if the given point is inside the polygon according to the specified fillRule; otherwise returns false.

        That says "inside" .....

        H 1 Reply Last reply
        1
        • JonBJ JonB

          @hobbyProgrammer

          (so not just that QPolygon contains a point QPoint, since those are only for the outside)

          What "outside"? https://doc.qt.io/qt-5/qpolygon.html#containsPoint

          Returns true if the given point is inside the polygon according to the specified fillRule; otherwise returns false.

          That says "inside" .....

          H Offline
          H Offline
          hobbyProgrammer
          wrote on last edited by
          #3

          @JonB I save my qpolygon's in a qvector. When I try qv_polygons.at(i).contains it doesn't seem to work properly, but I also don't get the oppertunity to use containsPoint.

          I get the error:

          const class QVecor<QPoint> had no member named containsPoint;
          

          with outside I mean on the edge/corner points that are stored within QPolygon.

          JonBJ 1 Reply Last reply
          0
          • H hobbyProgrammer

            @JonB I save my qpolygon's in a qvector. When I try qv_polygons.at(i).contains it doesn't seem to work properly, but I also don't get the oppertunity to use containsPoint.

            I get the error:

            const class QVecor<QPoint> had no member named containsPoint;
            

            with outside I mean on the edge/corner points that are stored within QPolygon.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @hobbyProgrammer
            What's a QVecor[sic.]?
            Check what your qv_polygons.at(i) actually is, because the error message tells you it thinks it's a QVecor<QPoint>, not a QPolygon. Ah, I see

            A QPolygon object is a QVector<QPoint>.

            You may need something like a <static_cast>(QPolygon)? Or possibly QPolygon(const QVector<QPoint> &points) to get a (new) QPolygon out of the points vector, I don't know.

            H 1 Reply Last reply
            1
            • JonBJ JonB

              @hobbyProgrammer
              What's a QVecor[sic.]?
              Check what your qv_polygons.at(i) actually is, because the error message tells you it thinks it's a QVecor<QPoint>, not a QPolygon. Ah, I see

              A QPolygon object is a QVector<QPoint>.

              You may need something like a <static_cast>(QPolygon)? Or possibly QPolygon(const QVector<QPoint> &points) to get a (new) QPolygon out of the points vector, I don't know.

              H Offline
              H Offline
              hobbyProgrammer
              wrote on last edited by
              #5

              @JonB oh that was really stupid. I was meant to check another QVector of QPolygons...

              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