dF.*_*dF. 7 geometry qt drawing qgraphicsview
我正在尝试测试给定点(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
Run Code Online (Sandbox Code Playgroud)