Ejemplo n.º 1
0
 def _scaleToFit(self):
     widget = self.__centralWidget
     if widget is None or not self.__fitInView:
         return
     vpsize = self.__viewportContentSize()
     size = widget.size()
     if not size.isEmpty():
         sc = scaled(size, vpsize, self.__aspectMode)
         sx = sc.width() / size.width()
         sy = sc.height() / size.height()
         self.setTransform(QTransform().scale(sx, sy))
Ejemplo n.º 2
0
    def pixmapTransform(self) -> QTransform:
        if self.__pixmap.isNull():
            return QTransform()

        pxsize = QSizeF(self.__pixmap.size())
        crect = self.contentsRect()
        transform = QTransform()
        transform = transform.translate(crect.left(), crect.top())

        if self.__scaleContents:
            csize = scaled(pxsize, crect.size(), self.__aspectMode)
        else:
            csize = pxsize

        xscale = csize.width() / pxsize.width()
        yscale = csize.height() / pxsize.height()

        return transform.scale(xscale, yscale)
Ejemplo n.º 3
0
 def sizeHint(self, which, constraint=QSizeF(-1, -1)) -> QSizeF:
     if which == Qt.PreferredSize:
         sh = QSizeF(self.__pixmap.size())
         if self.__scaleContents:
             sh = scaled(sh, constraint, self.__aspectMode)
         return sh
     elif which == Qt.MinimumSize:
         if self.__scaleContents:
             return QSizeF(0, 0)
         else:
             return QSizeF(self.__pixmap.size())
     elif which == Qt.MaximumSize:
         if self.__scaleContents:
             return QSizeF()
         else:
             return QSizeF(self.__pixmap.size())
     else:
         # Qt.MinimumDescent
         return QSizeF()