title: How draw Polygon from MouseEvents on top of Image in Qlabel
body: <p>Using Python , PYQT5 I want to draw a Polygon on top a Image, which is in a Qlabel widget. I used a simple Qmainwindow with a label widget generated in QT designer (code is below).</p>
  
  <p>I am aware that there are several informations out abaut drawing in a Qmainwindow like here:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/52916101/pyqt5-how-to-interactively-paint-on-image-within-qlabel-widget">PyQT5: How to interactively paint on image within QLabel Widget?</a> - which has no solution within a Qlabel widget.</p></li>
  <li><p><a href="https://stackoverflow.com/questions/55689354/draw-over-image-in-a-qlabel-with-pyqt5">Draw over image in a QLabel with PyQt5</a> - marked solution is unclear because also painting on top of Qlabel is not solved</p></li>
  <li><p><a href="https://stackoverflow.com/questions/55078456/pyqt5-drawing-line">PYQT5 drawing line</a> - paintevent on Qlabel is working, but not on top of the image</p></li>
  <li><p><a href="https://stackoverflow.com/questions/51768266/painting-in-a-qlabel-with-paintevent">Painting in a QLabel with paintEvent</a> - but also not solved to draw on top of an image.</p></li>
  </ul>
  
  <p>Let me know, if you have a solution for this problem.</p>
  
  <pre><code>import sys
  from PyQt5.QtCore import Qt
  from PyQt5 import QtWidgets, uic, QtCore, QtGui
  from PyQt5.QtGui import QPixmap, QPainter, QPolygon, QPen, QBrush
  from PyQt5.QtCore import QPoint
  
  from polygon_ui import Ui_MainWindow
  
  
  class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
      def __init__(self, *args, obj=None, **kwargs):
          super(MainWindow, self).__init__(*args, **kwargs)
          self.setupUi(self)
  
          pixmap = QPixmap("img.png")
          self.label.setPixmap(pixmap)
  
          self.label.mousePressEvent = self.getPixel
          self.pol = []
  
      def getPixel(self, event):
          x = event.pos().x()
          y = event.pos().y()
  
          self.pol.append(QPoint(int(x),int(y)))
  
          print(x,y, self.pol)
  
      def paintEvent(self, event):
          painter = QPainter(self)
          #painter.drawPixmap(self.rect(), self.image)
  
          painter.setPen(QPen(Qt.black, 5, Qt.SolidLine))
          painter.setBrush(QBrush(Qt.red, Qt.VerPattern))
  
          #points = QPolygon([ QPoint(10,10), QPoint(10,100),
          #     QPoint(100,10), QPoint(100,100)])
  
          points = QPolygon(self.pol)
          painter.drawPolygon(points)
  
      def mouseMoveEvent(self, event):
          pass
  
  if __name__ == '__main__':
      app = QtWidgets.QApplication(sys.argv)
      window = MainWindow()
      window.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>the code for polygon_ui is here - was simply generated by QT-Designer using Mainwindow + Qlabel:</p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  
  
  class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
          MainWindow.setObjectName("MainWindow")
          MainWindow.resize(621, 641)
          self.centralwidget = QtWidgets.QWidget(MainWindow)
          self.centralwidget.setObjectName("centralwidget")
          self.label = QtWidgets.QLabel(self.centralwidget)
          self.label.setGeometry(QtCore.QRect(10, 10, 600, 600))
          self.label.setObjectName("label")
          MainWindow.setCentralWidget(self.centralwidget)
          self.menubar = QtWidgets.QMenuBar(MainWindow)
          self.menubar.setGeometry(QtCore.QRect(0, 0, 621, 21))
          self.menubar.setObjectName("menubar")
          MainWindow.setMenuBar(self.menubar)
          self.statusbar = QtWidgets.QStatusBar(MainWindow)
          self.statusbar.setObjectName("statusbar")
          MainWindow.setStatusBar(self.statusbar)
  
          self.retranslateUi(MainWindow)
          QtCore.QMetaObject.connectSlotsByName(MainWindow)
  
      def retranslateUi(self, MainWindow):
          _translate = QtCore.QCoreApplication.translate
          MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
          self.label.setText(_translate("MainWindow", "TextLabel"))
  
  </code></pre>