拉伸图像而不保持纵横比

时间:2021-07-04 03:04:05

标签: python pyqt pyqt5

我通过 PyQt 在 QLabel self.dlg.image_label 对象中显示图像。当我调整小部件的大小时,图像的结果是拉伸而不是保持纵横比。我想要的是图像可以在保持纵横比的同时调整大小。

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()

这是我拉伸小部件时的结果:

enter image description here enter image description here

0 个答案:

没有答案