我正在尝试测试给定的点(x, y)是否位于或接近QGraphicsPathItem的轮廓。
使用QGraphicsItem.contains()或.collidesWithItem() / Path()是不行的:如果点包含在路径内部的区域内,则返回True,而我只想测试大纲上的点。我怎样才能做到这一点?
发布于 2010-02-06 22:42:38
在发布这个问题之后,我找到了以下解决方案:
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 pathhttps://stackoverflow.com/questions/2214911
复制相似问题