代码之家  ›  专栏  ›  技术社区  ›  dF.

如何测试与qgraphicspathitem大纲的接近程度?

  •  7
  • dF.  · 技术社区  · 15 年前

    我在测试一个给定的点 (x, y) 位于或靠近 概述 A的 QGraphicsPathItem .

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

    1 回复  |  直到 15 年前
        1
  •  2
  •   dF.    15 年前

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

        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