I am trying to check if a given point (x, y) on or near the QGraphicsPathItem contour.
(x, y)
QGraphicsPathItem
Using QGraphicsItem.contains() or .collidesWithItem() / Path() will not: they return True if the point is contained within the area inside the path, while I want to check only the points on the path. How can i do this?
QGraphicsItem.contains()
.collidesWithItem() / Path()
After posting the question, I found the following solution:
path = QPainterPath(...) # Path we are testing against point = QPointF(...) # Current position stroker = QPainterPathStroker() stroker.setWidth(10) # Distance which we consider "on" the path stroke = stroker.createStroke(path) if stroke.contains(point): # point is on path