[SOLVED] Setting QIcon() pixmap from URL

Issue

how can i set Qicon from a url in PYQT , can you give me an example?

Solution

a basic example would be:

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

Answered By – mata

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *