Setting the Windows taskbar icon in PyQt

前端 未结 4 1795
小鲜肉
小鲜肉 2020-12-09 08:10

I\'m working on an applcation in Python\'s PyQt4 and cannot find how to change the taskbar icon. I made my .ui files in Qt\'s Designer, where I can change the windowIc

4条回答
  •  余生分开走
    2020-12-09 08:48

    You need to call setWindowIcon(...) on the window, not on the application.

    Here's an example, which works for me:

    #!/usr/bin/env python3
    
    import os
    import sys
    import subprocess
    import os.path
    
    from PyQt4 import QtGui
    from PyQt4 import QtCore
    
    class MyWin(QtGui.QMainWindow):
        def __init__(self, parent=None):
            super(MyWin, self).__init__(parent)
            self.setWindowTitle("My Window")
            self.setWindowIcon(QtGui.QIcon('test_icon.png'))
            self.show()
    
    def main(args):
        app = QtGui.QApplication([])
    
        ww= MyWin()
        sys.exit(app.exec_())
    
    if __name__ == '__main__':
        main(sys.argv[1:])
    

提交回复
热议问题