我一直在尝试从URL设置图像到QLabel.但我没有运气.以下是我现在尝试做的事情:
import urllib, cStringIO
img_file = cStringIO.StringIO(urllib.urlopen(image_url).read())
image_file = Image.open(img_file)
Run Code Online (Sandbox Code Playgroud)
然后将其设置为QImage:
final_image = QImage(image_file)
self.emit(SIGNAL("finished(QImage)"),
final_image
)
Run Code Online (Sandbox Code Playgroud)
图像将从线程传递回主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)
Run Code Online (Sandbox Code Playgroud)
这样做我得到错误:
QPixmap::scaled: Pixmap is a null pixmap
Run Code Online (Sandbox Code Playgroud)
无论如何要解决这个问题,还是以不同的方式解决这个问题?