QPainter paints garbage
Posted
by DSblizzard
on Stack Overflow
See other posts from Stack Overflow
or by DSblizzard
Published on 2010-06-07T02:45:12Z
Indexed on
2010/06/07
2:52 UTC
Read the original article
Hit count: 385
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/content_round.php?page=done&l=img697/5395/qpaintergarbage1.jpg
When lines (1) and (2) are uncommented things doesn't become much better: http://img63.imageshack.us/content_round.php?page=done&l=img63/9693/qpaintergarbage0.jpg
Please help me to solve this problem.
© Stack Overflow or respective owner