我正在尝试测试给定点(x, y)
是否位于或靠近a的轮廓QGraphicsPathItem
。
使用QGraphicsItem.contains()
或.collidesWithItem() / Path()
不使用:如果该点包含在路径内部的区域内,它们也会返回 True,而我只想测试轮廓上的点。我怎样才能做到这一点?
我正在尝试测试给定点(x, y)
是否位于或靠近a的轮廓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