PyQtGraph自定义图形项使白色正方形显示在原点

2024-10-02 00:34:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个PyQtGraph自定义数据项,它导致一个不在数据中的白色正方形出现在原点。白色的方块只有在你放大一点的时候才可见。你知道吗

自定义图形项:

class ParticalRendererItem(pg.GraphicsObject):
    def __init__(self,data):
        pg.GraphicsObject.__init__(self)
        self.data = data
        self.generatePicture()

    def generatePicture(self):
        self.picture = QtGui.QPicture()
        p = QtGui.QPainter(self.picture)
        p.setPen(pg.mkPen('w'))
        for partical in self.data:
            prodPos = QtCore.QPoint(partical.xProd,partical.yProd)
            momentumPos = QtCore.QPoint(partical.px,partical.py)
            p.drawLine(prodPos,momentumPos)
        p.end()
    def paint(self,p,*args):
        p.drawPicture(0,0,self.picture)
    def boundingRect(self):
        return QtCore.QRectF(self.picture.boundingRect())

数据是具有所有这些属性的类partical的列表。你知道吗

图表如下: The White Square

提前谢谢。你知道吗


Tags: 数据selfdatainitdefpgpicture白色

热门问题