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