from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QPainter
from PyQt5.QtCore import Qt, QPoint
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.widthApp, self.heightApp = 700, 550
self.pos = QPoint(120, 70) # +++
self.initUI()
def initUI(self):
self.setGeometry(600, 300, self.width(), self.height())
self.show()
def paintEvent(self, e):
self.paint = QPainter()
self.paint.begin(self)
self.paint.drawEllipse(self.pos, 100, 50) # +++
self.paint.end()
def mousePressEvent(self, e):
if e.buttons() == Qt.LeftButton:
self.pos = e.pos() # +++
self.update()
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
w = Example()
sys.exit(app.exec_())

from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QPainter, QPainterPath, QPen, QColor
from PyQt5.QtCore import Qt, QPoint
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.widthApp, self.heightApp = 700, 550
self.pos = QPoint(120, 70)
self.posList = [QPoint(120, 70),] # +
self.initUI()
def initUI(self):
self.setGeometry(600, 150, self.width(), self.height())
self.show()
def paintEvent(self, e):
self.paint = QPainter()
self.paint.begin(self)
self.paint.setPen(QPen(QColor("blue")))
self.drawLine(self.paint)
self.paint.setPen(QPen(QColor("red")))
self.paint.drawEllipse(self.pos, 10, 10)
###
for p in self.posList: # +
self.paint.drawEllipse(p, 10, 10)
self.paint.end()
def mousePressEvent(self, e):
if e.buttons() == Qt.LeftButton:
self.pos = e.pos()
self.posList.append(self.pos) # +
self.update()
def drawLine(self, qp):
qp.drawLine(300, 10, 300, 200)
path = QPainterPath()
path.moveTo(100, 200)
path.lineTo(300, 200)
qp.drawPath(path)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
w = Example()
sys.exit(app.exec_())
