Bonjour à tous je travaille sur PyQt5 pour faire un gui et j'ai intégré un widget pour dessiner sur la fenêtre principale, mais je veux utiliser un bouton pour effacer ce widget pour dessin J'utilise ce code, mais je ne comprends pas ce qui est mal avec elle, il ne semble pas fonctionner grâceComment faire une fonction de tableau claire pour un widget dans pyqt5
class Drawer(QWidget):
newPoint = pyqtSignal(QPoint)
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.setAttribute(QtCore.Qt.WA_StaticContents)
self.modified = False
self.scribbling = False
imageSize = QtCore.QSize(9500, 9500)
h=400
w=400
self.image = QtGui.QImage()
self.image=QtGui.QImage(w,h,QtGui.QImage.Format_RGB32)
self.path = QPainterPath()
def setPenColor(self, newColor):
self.myPenColor = newColor
def setPenWidth(self, newWidth):
self.myPenWidth = newWidth
def clearImage(self):
self.image.fill(QtGui.qRgb(255, 255, 255)) ## switch it to else
self.modified = True
self.update()
def paintEvent(self, event):
painter = QPainter(self)
painter.setPen(QColor(0, 0, 0))
painter.setFont(QFont('Decorative', 10))
painter.drawImage(event.rect(), self.image)
painter.drawPath(self.path)
def mousePressEvent(self, event):
self.path.moveTo(event.pos())
self.update()
def mouseMoveEvent(self, event):
self.path.lineTo(event.pos())
self.newPoint.emit(event.pos())
self.update()
def sizeHint(self):
return QSize(200, 200)