Setting the Windows taskbar icon in PyQt

It seems to me that the problem may be caused by lack of icon with the right size. The following setup worked for me in PyQT4:

# set app icon    
app_icon = QtGui.QIcon()
app_icon.addFile('gui/icons/16x16.png', QtCore.QSize(16,16))
app_icon.addFile('gui/icons/24x24.png', QtCore.QSize(24,24))
app_icon.addFile('gui/icons/32x32.png', QtCore.QSize(32,32))
app_icon.addFile('gui/icons/48x48.png', QtCore.QSize(48,48))
app_icon.addFile('gui/icons/256x256.png', QtCore.QSize(256,256))
app.setWindowIcon(app_icon)

I have got a task bar icon in Windows 7 and correct icons in all windows without any changes to ui files.


This problem is caused by some peculiarities in how taskbar icons are handled on the Windows platform.

See this answer for details, along with a workaround using ctypes.