Qpaint Clear Drawing Area
-
I've been looking for 2 weeks for a simple example to draw some lines with the Qpen then clear the drawing area. I've tried hundreds of things I found by searching but none just clear the lines I've drawn. Is there an example of drawing lines then clearing them?
In a nutshell I open a DXF file and get the coordinates for the entities then draw them, this all works fine and dandy but when I open a new drawing the old drawing is still there. I've tried eraseRect, fillRect and many more.
JT
-
@JThornton Why not simply draw a filled rectangle over the whole drawing area?
-
Because it simply don't work or I simply don't understand the correct syntax.
def paintEvent(self, e): qp = QPainter(self.openGLWidget) self.clearPlot(qp) self.drawLines(qp) def clearPlot(self, qp): #qp.eraseRect(0, 0, self.canvasWidth, self.canvasHeight) qp.fillRect(0, 0, self.canvasWidth, self.canvasHeight, QBrush(Qt.SolidPattern)) def drawLines(self, qp): # SolidLine pen = QPen(Qt.white, 1, Qt.SolidLine) qp.setPen(pen) t = QTransform() t.translate(self.canvasWidth / 2, self.canvasHeight / 2) qp.setTransform(t) if len(self.entityList) > 0: for l in self.entityList: if l[0] == 'LINE': qp.drawLine(l[2], l[3], l[4], l[5])
-
@JThornton said in Qpaint Clear Drawing Area:
def paintEvent(self, e):
qp = QPainter(self.openGLWidget)This is not how paintEvent works. See https://doc.qt.io/qt-5/qpainter.html
"Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent()".
You're trying to draw on another widget (self.openGLWidget).
You need to do this in paintEvent in openGLWidget class. -
Hi,
You can do that from the "Topic Tools" button.
There also some interesting options in the three dot menu beside the up/down vote arrows.