标签:pyqt setwindowicon pyqt任务栏图标
今天在运行一个pyqt程序的时候发现setWindowIcon这个函数起了一半的作用,学Qt的都知道这个函数同时设置了程序的两个地方的图标显示,
第一处在程序的左上角一个小图标(只实用于window和linux,mac没有的),第二处就是任务栏的图标,如下图:
在使用pyqt的时候你发现只有第一处设置成功了,而第二处则显示的是pythonw.exe的图标,
谷歌找了一下,解决了,下面就是详细描述,英文稍差一点的同学就直接看解决方法吧,话说博主的英文也是烂的一塌糊涂
I‘ve found the answer, after some digging.
In Windows 7, the taskbar is not for "Application Windows" per se, it‘s for "Application User Models". For example, if you have several different instances of your application running, and each instance has its own icon, then they will all be grouped under a single taskbar icon. Windows uses various heuristics to decide whether different instances should be grouped or not, and in this case it decided that everything hosted by Pythonw.exe should be grouped under the icon for Pythonw.exe.
The correct solution is for Pythonw.exe to tell Windows that it is merely hosting other applications. Perhaps a future release of Python will do this. Alternatively, you can add a registry key to tell Windows that Pythonw.exe is just a host rather than an application in its own right. See MSDN documentation forAppUserModelIDs.
Alternatively, you can use a Windows call from Python, to explicitly tell Windows what the correct AppUserModelID is for this process:
简而言之,我的理解就是pyqt是要给python解释的,也就是说windows在运行的时候认识到的是python,而你写的程序则被看做是python这个主程序的一个子程序,这个时候你就要站出来告诉windows,我这个窗口强制使用单独的AppUserModelID ,现在这个窗口拥有了一个新资源支配权限,更多的可定制。如果我的理解有误,还请留言指正.
那到底要怎么告诉windows呢:
import ctypes ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")
以上只适用于windows,
但如果你不幸用的linux怎么办,其实更简单,用过ubuntu的都知道每一个桌面软件在/usr/share/applications目录下面都对应一个图标文件 .desktop
等你软件做好打包的时候自动添加这么一个文件就行了
当然用C++&Qt的同学就不会遇到这样的问题了。
标签:pyqt setwindowicon pyqt任务栏图标
原文地址:http://blog.csdn.net/jiecooner/article/details/42238903