from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Application(QMainWindow):
def __init__(self):
super(Application, self).__init__()
self.setWindowIcon(QtGui.QIcon('icon.png'))
我想设置一个窗口图标(窗口左上角),但正常的图标消失了。如何用PyQt5设置窗口图标?
我尝试了许多图标分辨率(8x8,16x16,32x32,64x64)和扩展名(.png和.ico)。
我在做什么错?
使用绝对路径。 – ekhumoro
谢谢,但它不起作用。我试着用self.setWindowIcon(QtGui.QIcon('C:/Users/John/PycharmProjects/pythonproject/icon.png'))。另外,我必须在导入中添加QtGui才能获得QIcon。我甚至不确定这是用PyQt5做的好方法。 – HumanAfterAll
如果您将图标添加到一个按钮? PS:QtGui.QImageReader.supportedImageFormats()是什么输出? – ekhumoro