从URL设置QIcon()pixmap

时间:2012-05-24 10:48:34

标签: python qt pyqt pyqt4

如何从PYQT的网址设置Qicon,你能举个例子吗?

1 个答案:

答案 0 :(得分:6)

一个基本的例子是:

from PyQt4.QtGui import *
from PyQt4.QtCore import QUrl
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest

app = QApplication([])
url = "http://www.google.com/favicon.ico"
lbl = QLabel("loading...")
nam = QNetworkAccessManager()

def finishRequest(reply):
    img = QImage()
    img.loadFromData(reply.readAll())
    lbl.setPixmap(QPixmap(img))

nam.finished.connect(finishRequest)
nam.get(QNetworkRequest(QUrl(url)))
lbl.show()
app.exec_()