Check if a QPoint lies within a QPolygon
-
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. -
@hobbyProgrammer
What's aQVecor
[sic.]?
Check what yourqv_polygons.at(i)
actually is, because the error message tells you it thinks it's aQVecor<QPoint>
, not aQPolygon
. Ah, I seeA QPolygon object is a QVector<QPoint>.
You may need something like a
<static_cast>(QPolygon)
? Or possiblyQPolygon(const QVector<QPoint> &points)
to get a (new)QPolygon
out of the points vector, I don't know. -
(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" .....
-
@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.
-
@hobbyProgrammer
What's aQVecor
[sic.]?
Check what yourqv_polygons.at(i)
actually is, because the error message tells you it thinks it's aQVecor<QPoint>
, not aQPolygon
. Ah, I seeA QPolygon object is a QVector<QPoint>.
You may need something like a
<static_cast>(QPolygon)
? Or possiblyQPolygon(const QVector<QPoint> &points)
to get a (new)QPolygon
out of the points vector, I don't know.