我一直在尝试从URL设置QLabel的图像,但是没有成功。以下是我目前的尝试方法:
import urllib, cStringIO
img_file = cStringIO.StringIO(urllib.urlopen(image_url).read())
image_file = Image.open(img_file)
然后将其设置为QImage:
final_image = QImage(image_file)
self.emit(SIGNAL("finished(QImage)"),
final_image
)
图像从一个线程传回到主GUI中的方法。
def set_image(self, final_image):
self.main_picture_pixmap = QPixmap.fromImage(final_image).scaled(
QSize(self.picture_label.size()),
Qt.KeepAspectRatio,
Qt.FastTransformation
)
self.picture_label.setPixmap(self.main_picture_pixmap)
这样做会出现错误:
QPixmap::scaled: Pixmap is a null pixmap
有没有办法修复这个问题,或者有没有其他方法来解决这个问题?