我通过 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()
这是我拉伸小部件时的结果: