title: How to implement mouseMoveEvent on QPainter?
body: <p>I have the same question with this <a href="https://stackoverflow.com/questions/49699848/pyqt5-how-to-draw-a-dot-on-mouse-click-position">question</a> and I found this <a href="https://stackoverflow.com/a/49700136/15870976">answer</a> to that question very helpful.</p>
  <p>I have tried to run the provided code in the answer and it worked.</p>
  <p><strong>The Code included with the provided <a href="https://stackoverflow.com/a/49700136/15870976">answer</a>:</strong></p>
  <pre><code>import random
  import sys
  
  from PyQt5 import QtCore, QtGui, QtWidgets
  
  
  class Window(QtWidgets.QMainWindow):
      def __init__(self):
          super(Window, self).__init__()
  
          self.rect = QtCore.QRect()
          self.drag_position = QtCore.QPoint()
  
          button = QtWidgets.QPushButton(&quot;Add&quot;, self)
          button.clicked.connect(self.on_clicked)
  
          self.resize(640, 480)
  
      @QtCore.pyqtSlot()
      def on_clicked(self):
          if True:
              self.rect = QtCore.QRect(
                  QtCore.QPoint(*random.sample(range(200), 2)), QtCore.QSize(100, 100)
              )
              self.update()
  
      def paintEvent(self, event):
          super().paintEvent(event)
          if not self.rect.isNull():
              painter = QtGui.QPainter(self)
              painter.setRenderHint(QtGui.QPainter.Antialiasing)
              painter.setPen(QtGui.QPen(QtCore.Qt.black, 5, QtCore.Qt.SolidLine))
              painter.drawEllipse(self.rect)
  
      def mousePressEvent(self, event):
          print(1)
          if (
              2 * QtGui.QVector2D(event.pos() - self.rect.center()).length()
              &lt; self.rect.width()
          ):
              self.drag_position = event.pos() - self.rect.topLeft()
          super().mousePressEvent(event)
  
      def mouseMoveEvent(self, event):
          print(2)
          if not self.drag_position.isNull():
              self.rect.moveTopLeft(event.pos() - self.drag_position)
              self.update()
          super().mouseMoveEvent(event)
  
      def mouseReleaseEvent(self, event):
          print(3)
          self.drag_position = QtCore.QPoint()
          super().mouseReleaseEvent(event)
  
  
  if __name__ == &quot;__main__&quot;:
      app = QtWidgets.QApplication(sys.argv)
      Rect = Window()
      Rect.show()
      sys.exit(app.exec_())
  </code></pre>
  <p><strong>My Question:</strong></p>
  <p>How can I move these &quot;points&quot; when dragging them. My first thought is subclassing the <code>QPainter</code> and tweaking inside that class the events but when I read the docs, I found no method where I can move the &quot;points&quot;. I'm really stuck here right now and I can't find the correct implementation for this.</p>