0

私はこのコードを持っています:

def paintEvent(self, paintEvent):
    self._painter.begin(self)
    try:
        while True:
            color, rectangle = self._paint_queue.popleft()
            self._painter.fillRect(rectangle, color)
    except IndexError:
        pass
    finally:
        self._painter.end()

def drawInstruction(self, ptr, instruction):
    rectangle = QtCore.QRect(
             (ptr % self.cols)*CELL_SIZE,
             math.floor(ptr/float(self.cols))*CELL_SIZE,
             CELL_SIZE,
             CELL_SIZE)
    self._paint_queue.append((opcode2color[instruction.opcode],
        rectangle))
    self.update()

そして、drawInstruction()を呼び出すたびに、すでに描画されているものはすべてクリアされます。新しい長方形だけが残ります。

また、drawInstruction()は頻繁に呼び出されるため、drawInstruction()を呼び出すたびにすべてを再描画することは解決策ではありません。

4

1 に答える 1

4

you have to redraw the widget content on each paintEvent, there's no other way.

maybe in your case it woule be better to draw on a other paint device (QImage, QPixmap, QPicture, ...), and just paint that on each paint event.

于 2012-05-06T17:47:47.410 に答える