How to check proximity to the QGraphicsPathItem contour?

I am trying to check if a given point (x, y) on or near the QGraphicsPathItem contour.

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?

+7
qt geometry drawing qgraphicsview
source share
1 answer

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 
+2
source share

All Articles