title: get real size of QPixmap in Qlabel
body: <p>Is there some simple way in PyQt5 to get real dimensions of the pixmap displayed in QLabel? I am trying to select part of the image with rubber band. But I can't find a way to limit the rubberband only to pixmap. The QLabel.pixmap().rect() returns dimensions of the whole QLabel not only the pixmap. The problem arises when the pixmap is scaled and there are stripes on the sides of the picture. </p>
  
  <p>The Example image</p>
  
  <p><img src="https://i.stack.imgur.com/Q6SRb.jpg" alt=""> </p>
  
  <p>Example image 2</p>
  
  <p><img src="https://i.stack.imgur.com/dkZqD.jpg" alt=""> </p>
  
  <p>I posted are quite self explanatory. I don't want the rubberband to be able to move out of the picture to the white stripes.</p>
  
  <pre><code>class ResizableRubberBand(QWidget):
  
      def __init__(self, parent=None):
          super(ResizableRubberBand, self).__init__(parent)
  
          self.aspect_ratio = None
  
          self.setWindowFlags(Qt.SubWindow)
          self.layout = QHBoxLayout(self)
          self.layout.setContentsMargins(0, 0, 0, 0)
  
          self.grip1 = QSizeGrip(self)
          self.grip2 = QSizeGrip(self)
          self.layout.addWidget(self.grip1, 0, Qt.AlignLeft | Qt.AlignTop)
          self.layout.addWidget(self.grip2, 0, Qt.AlignRight | Qt.AlignBottom)
  
          self.rubberband = QRubberBand(QRubberBand.Rectangle, self)
          self.rubberband.setStyle(QStyleFactory.create("Fusion"))
          self.rubberband.move(0, 0)
          self.rubberband.show()
          self.show()
  
  
  class ResizablePixmap(QLabel):
  
      def __init__(self, bytes_image):
  
          QLabel.__init__(self)
          self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
          self.setAlignment(Qt.AlignVCenter | Qt.AlignHCenter)
          self.setStyleSheet("background-color:#ffffff;")
  
          self.update_pixmap(bytes_image)
  
      def resizeEvent(self, event):
  
          if event:
              x = event.size().width()
              y = event.size().height()
          else:
              x = self.width()
              y = self.height()
  
          self.current_pixmap = self._bytes2pixmap(self.bytes_image_edit)
          self.setPixmap(self.current_pixmap.scaled(x, y, Qt.KeepAspectRatio))
          self.resize(x, y)
  
      def update_pixmap(self, bytes_image):
  
          self.bytes_image_edit = bytes_image
  
          self.current_pixmap = self._bytes2pixmap(bytes_image)
          self.setPixmap(self.current_pixmap)
  
          self.resizeEvent(None)
  
      @staticmethod
      def _bytes2pixmap(raw_image):
  
          image = QImage()
          image.loadFromData(raw_image)
          return QPixmap(image)
  
      @staticmethod
      def _pixmap2bytes(pixmap):
  
          byte_array = QByteArray()
          buffer = QBuffer(byte_array)
          buffer.open(QIODevice.WriteOnly)
          pixmap.save(buffer, 'PNG')
          return byte_array.data()
  
      @property
      def image_dims(self):
          return self.width(), self.height()
  
      def force_resize(self, qsize):
          self.resizeEvent(QResizeEvent(qsize, qsize))
  
  
  class SelectablePixmap(ResizablePixmap):
  
      def __init__(self, bytes_image):
  
          super().__init__(bytes_image)
  
          self.currentQRubberBand = None
          self.move_rubber_band = False
          self.rubber_band_offset = None
  
      def cancel_selection(self):
          self.currentQRubberBand.hide()
          self.currentQRubberBand.deleteLater()
          self.currentQRubberBand = None
          self.selectionActive.emit(False)
  
      def mousePressEvent(self, eventQMouseEvent):
  
          if not self.currentQRubberBand:
              self.currentQRubberBand = ResizableRubberBand(self)
              self.selectionActive.emit(True)
  
          if self.currentQRubberBand.geometry().contains(eventQMouseEvent.pos()):
              self.move_rubber_band = True
              self.rubber_band_offset = (eventQMouseEvent.pos() -
                                         self.currentQRubberBand.pos())
          else:
              self.originQPoint = eventQMouseEvent.pos()
              if self.pixmap().rect().contains(self.originQPoint):
                  self.currentQRubberBand.setGeometry(QRect(self.originQPoint,
                                                            QSize()))
                  self.currentQRubberBand.show()
  
      def mouseMoveEvent(self, eventQMouseEvent):
  
          if self.move_rubber_band:
              pos = eventQMouseEvent.pos() - self.rubber_band_offset
              if self.pixmap().rect().contains(pos):
                  self.currentQRubberBand.move(pos)
          else:
              rect = QRect(self.originQPoint, eventQMouseEvent.pos())
              self.currentQRubberBand.setGeometry(rect.normalized())
  
      def mouseReleaseEvent(self, eventQMouseEvent):
  
          if self.move_rubber_band:
              self.move_rubber_band = False
  </code></pre>