Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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.
@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 == 'LINE': qp.drawLine(l, l, l, l)
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.
Ok, I'm finding that out now. Thanks for the info.
I don't see a way to mark this solved, anyone have a clue?
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.