特定の点がの輪郭上または輪郭の(x, y)
近くにあるかどうかをテストしようとしています。QGraphicsPathItem
使用するQGraphicsItem.contains()
か.collidesWithItem() / Path()
しないか:ポイントがパスの内部の領域内に含まれている場合もTrueを返しますが、アウトライン上のポイントのみをテストします。どうすればそれを達成できますか?
特定の点がの輪郭上または輪郭の(x, y)
近くにあるかどうかをテストしようとしています。QGraphicsPathItem
使用するQGraphicsItem.contains()
か.collidesWithItem() / Path()
しないか:ポイントがパスの内部の領域内に含まれている場合もTrueを返しますが、アウトライン上のポイントのみをテストします。どうすればそれを達成できますか?
質問を投稿した後、私は次の解決策を見つけました:
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