I'm trying to learn PyQt. While going over a tutorial to get the basics I've encountered a problem with QIcon.
The following code is supposed to create a simple window with an icon from an image called 'web.png':
import os
import sys
import PyQt5
dirname = os.path.dirname(PyQt5.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QIcon
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 300, 220)
self.setWindowTitle('Icon')
self.setWindowIcon(QIcon('web.png'))
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
However, the resulting window contains a standard icon and not the wanted image:
The image web.png is contained within the current working directory. I use Python 3.5.1 and PyQt 5 with Qt 5.6.2.
Any help would be appreciated.
imageformats
plugins. Seems like you miss them. – ilotXXI