class PaintScene(QGraphicsScene):
prev = None
color = Qt.black
width = 10
strong = 10
def __init__(self):
super().__init__()
pass
def mousePressEvent(self, event):
self.addEllipse(
event.scenePos().x() - self.width / 2,
event.scenePos().y() - self.width / 2,
self.width,
self.width,
QPen(Qt.NoPen),
QBrush(self.color))
self.prev = event.scenePos()
def mouseReleaseEvent(self, event):
self.prev = None
def mouseMoveEvent(self, event):
if self.prev:
self.addLine(
self.prev.x(),
self.prev.y(),
event.scenePos().x(),
event.scenePos().y(),
QPen(self.color, self.width, Qt.SolidLine, Qt.RoundCap))
self.prev = event.scenePos()
def clear_area(self):
self.clear()