设置从URL QIcon()像素图(Setting QIcon() pixmap from URL)

2019-09-17 11:08发布

如何设置Qicon从PyQt的一个网址,你可以给我一个例子吗?

Answer 1:

一个基本的例子是:

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


文章来源: Setting QIcon() pixmap from URL