7

我正在尝试测试给定点(x, y)是否位于或靠近a的轮廓QGraphicsPathItem

使用QGraphicsItem.contains().collidesWithItem() / Path()不使用:如果该点包含在路径内部的区域内,它们也会返回 True,而我只想测试轮廓上的点。我怎样才能做到这一点?

4

1 回答 1

2

发布问题后,我找到了以下解决方案:

    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
于 2010-02-06T22:42:38.263 回答