开发者

QPainter paints garbage

开发者 https://www.devze.com 2023-01-02 17:51 出处:网络
Fragment of program code: def add_link(Item0Num, Item1Num): global Mw, View # Mw - MainWindow if Item0Num != Item1Num and not link_exists(Item0Num, Item1Num):

Fragment of program code:

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

This paints such garbage: http://img697.imageshack.us/img697/5395/qpaintergarbage1.jpg

QPainter paints garbage

When lines (1) and (2) are uncommented things doesn't become much better: http://img63.imageshack.us/img63/9693/qpaintergarbage0.jpg

QPainter paints garbage

Please help me to solve this problem.


It possibly happens because you don't clear background before painting. Or you clear it manually, but not all the area. Try setAutoFillBackground(true)

0

精彩评论

暂无评论...
验证码 换一张
取 消