Stretching image and not keeping aspect ratio

Viewed 113

I am displaying an image via PyQt in a QLabel self.dlg.image_label object. The result of the image is stretching and not keeping the aspect ratio while I resize the widget. What I want is that the image can resize while keeping the aspect ratio.

pixmap = QPixmap('path/to/image.jpg')
pixmap = pixmap.scaled(256, 256, Qt.KeepAspectRatio)
self.dlg.image_label.setPixmap(pixmap)
self.dlg.image_label.setScaledContents(True)
self.dlg.image_label.show()

Here are the results when I stretch the widget:

enter image description here enter image description here

0 Answers
Related