title: Resize QPaint drawRect by dragging the corner in order to select the ImageCrop Area
body: <p>I want the red rectangle resize like this</p>
  
  <p><img src="https://i.stack.imgur.com/NFaXG.gif" alt=""></p>
  
  <p>now</p>
  
  <p><img src="https://i.stack.imgur.com/8CuqN.png" alt=""></p>
  
  <p>I would like to keep Image remain the same size, but resize the Red Rectangle by dragging the corner of Red Rectangle, <strong>icon displayed at the same time</strong>.</p>
  
  <p>I reimplement QLabel to repaint the image and rectangle, but how can I reposition the icon at the corner?</p>
  
  <pre><code>import sys
  from PyQt5.QtCore import QPointF, QSize, QRectF, Qt
  from PyQt5.QtGui import QPixmap, QIcon, QPainter, QPen
  from PyQt5.QtWidgets import *
  
  class CropLabel(QLabel):
      def __init__(self, parent=None):
          super(CropLabel, self).__init__(parent)
          self.img = None
          self.left_top = QPointF(0, 0)
          self.bot_right = QPointF(0, 0)
          self.left_top_icon = QPixmap('images/lefttop-botright.png').scaled(QSize(25, 25))
  
      def setPixmap(self, QPixmap):
          self.img = QPixmap
          h, w = QPixmap.height(), QPixmap.width()
          self.bot_right = QPointF(self.left_top.x() + w, self.left_top.y() + h)
          self.resize(QSize(w, h))
  
  
      def paintEvent(self, QPaintEvent):
          if self.img is not None:
              painter = QPainter(self)
              painter.setRenderHint(QPainter.Antialiasing)
              painter.drawPixmap(self.left_top, self.img)
              painter.drawPixmap(self.left_top.x() - self.left_top_icon.width() / 2,
                                 self.left_top.y() - self.left_top_icon.height() / 2,
                                 self.left_top_icon)
  
              paintRect = QPen(Qt.red)
              paintRect.setWidth(3)
              painter.setPen(paintRect)
              painter.drawRect(QRectF(self.left_top, self.bot_right))
  
  class MainWindow(QWidget):
      def __init__(self):
          super(MainWindow, self).__init__()
          self.label = CropLabel(self)
          self.board_width = 100
          qPixmap = QPixmap('images/cat.jpg')
          self.resize(QSize(qPixmap.width() + self.board_width * 2, qPixmap.height() + self.board_width * 2))
          self.label.left_top = QPointF   (self.board_width, self.board_width)
          self.label.setPixmap(qPixmap)
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
      window = MainWindow()
      window.show()
      app.exec_()
  </code></pre>