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")

但如果你不幸用的linux怎么办,其实更简单,用过ubuntu的都知道每一个桌面软件在/usr/share/applications目录下面都对应一个图标文件 .desktop

等你软件做好打包的时候自动添加这么一个文件就行了

----------------------------------------------------

今天在家用linux试了一下才发现  ,在linux下setWindowIcon这个函数是没有问题的,也就是说这个问题只有在windows下面才有,所以上面linux解决办法,当我没说。。。

发布了133 篇原创文章 · 获赞 129 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/wofreeo/article/details/102504470
今日推荐