Qt 如何测试与QGraphicsPathItem轮廓的接近度?
我试图测试给定点Qt 如何测试与QGraphicsPathItem轮廓的接近度?,qt,geometry,drawing,qgraphicsview,Qt,Geometry,Drawing,Qgraphicsview,我试图测试给定点(x,y)是否位于QGraphicsPathItem的轮廓上或附近 使用或不使用:如果点包含在路径内部的区域内,则这些也将返回True,而我只想测试轮廓上的点。我怎样才能做到这一点 发布问题后,我找到了以下解决方案: path = QPainterPath(...) # Path we are testing against point = QPointF(...) # Current position stroker = QPainte
(x,y)
是否位于QGraphicsPathItem
的轮廓上或附近
使用或不使用:如果点包含在路径内部的区域内,则这些也将返回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