QPainter描绘垃圾

时间:2010-06-07 02:45:12

标签: qt graphics garbage qpainter

程序代码片段:

def add_link(Item0Num, Item1Num):
    global Mw, View # Mw - MainWindow
    if Item0Num != Item1Num and not link_exists(Item0Num, Item1Num):
        append( links_to(Item1Num), Item0Num )
        append( links_from(Item0Num), Item1Num )
        LinkGi = TLinkGi()
        Mw.Scene.addItem(LinkGi)
        LinkGi.setZValue(200)
        LinkGi.scale(1 / View.Scale, 1 / View.Scale)
        LinkGi.Item0Num = Item0Num
        LinkGi.Item1Num = Item1Num

class TLinkGi(QGraphicsItem):

    def paint(self, Painter, StyleOptionGraphicsItem, Widget):
        global Mw, View
        Pen = QPen(Qt.black, 1)
        Painter.setPen(Pen)
        X0, Y0 = task_center(self.Item0Num)
        self.setPos(X0, Y0)
        X1, Y1 = task_center(self.Item1Num)
        X, Y = int( (X1 - X0) * View.Scale ), int( (Y1 - Y0) * View.Scale )
        Painter.drawLine(0, 0, X, Y)
        #Mw.Scene.update(0, 0, Plan.Size, Plan.Size) # (1)
        #Mw.gvMain.repaint()                         # (2)

    def boundingRect(self):
        global View
        Rect = QRectF(0, 0, Plan.Size, Plan.Size)
        return Rect

这画这样的垃圾: http://img697.imageshack.us/img697/5395/qpaintergarbage1.jpg 1 http://img697.imageshack.us/img697/5395/qpaintergarbage1.jpg

当行(1)和(2)被取消注释时,事情并没有变得更好: http://img63.imageshack.us/img63/9693/qpaintergarbage0.jpg 2 http://img63.imageshack.us/img63/9693/qpaintergarbage0.jpg

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:2)

可能是因为您在绘画前没有清除背景。或者您手动清除它,但不是所有区域。尝试setAutoFillBackground(true)