def fitToWindow(self): """ Fits the image to the scroll area's size. """ sizeImage = self.lblImage.pixmap().size() height, width = sizeImage.height(), sizeImage.width() # If its smaller than self size, let it be normal size if height<self.size().height() and width<self.size().width(): self.normalSize() else: sizeImage.scale(self.size()*0.98, Qt.KeepAspectRatio) # Adjust the scale self.scale = float(sizeImage.height()) / height # Resize image to 95% self's size self.lblImage.resize(sizeImage) # Toggle windowFit (For resize events) self.windowFit = True