Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python QGraphicsPathItem和QPainterPathStroker的悬停区域不正确_Python_Qt_Pyqt_Drawing_Qgraphicsitem - Fatal编程技术网

Python QGraphicsPathItem和QPainterPathStroker的悬停区域不正确

Python QGraphicsPathItem和QPainterPathStroker的悬停区域不正确,python,qt,pyqt,drawing,qgraphicsitem,Python,Qt,Pyqt,Drawing,Qgraphicsitem,我正在编写一个继承自QGraphicsItemGroup的类,其主要子级是QGraphicsPathItem。整个过程用于绘制多段线。我想为线条设置一个合适的悬停系统,我重新实现了对象的shape方法,如下所示: def shape(self): stroker = QtWidgets.QPainterPathStroker() stroker.setWidth(10 * self.resolution) # resolution handles zoom and stuff

我正在编写一个继承自
QGraphicsItemGroup
的类,其主要子级是
QGraphicsPathItem
。整个过程用于绘制多段线。我想为线条设置一个合适的悬停系统,我重新实现了对象的
shape
方法,如下所示:

def shape(self):
    stroker = QtWidgets.QPainterPathStroker()
    stroker.setWidth(10 * self.resolution)  # resolution handles zoom and stuff
    path = stroker.createStroke(self.__path.path()).simplified()
    return path
在上面的代码片段中,
self.\u path
是我前面提到的
QGraphicsPathItem


为了简单起见,这里有一些图片。我在屏幕上看到的我画的线:

我想要的悬停区域:

我当前使用重新实现的
shape
方法的悬停区域如上所示:

正如您所猜测的,这样的选择区域几乎没有任何用途。最糟糕的是,我尝试使用完全相同的方法生成线条的轮廓,然后使用
toFillPolygon
生成一个多边形,通过向对象添加
QGraphicsPolygonItem
子对象,我在同一对象中渲染了该多边形:屏幕上显示的形状正是我想要的,但是当我使用相同的路径通过
shape
创建悬停区域时,它会给我一个无用的悬停区域(图3)

那么,您知道为什么使用
QPainterPathStroker
获得的路径允许我显示一个似乎与我想要的悬停区域完全对应的多边形,但是当我在
形状中使用该路径时,获得的覆盖区域是不可靠的吗?如果是,您知道如何解决此问题吗