pyqt任务栏图标问题
2014-12-29 16:34
876 查看
今天在运行一个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呢:
以上只适用于windows,
但如果你不幸用的linux怎么办,其实更简单,用过ubuntu的都知道每一个桌面软件在/usr/share/applications目录下面都对应一个图标文件 .desktop
等你软件做好打包的时候自动添加这么一个文件就行了
----------------------------------------------------
今天在家用linux试了一下才发现 ,在linux下setWindowIcon这个函数是没有问题的,也就是说这个问题只有在windows下面才有,所以上面linux解决办法,当我没说。。。
第一处在程序的左上角一个小图标(只实用于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
等你软件做好打包的时候自动添加这么一个文件就行了
----------------------------------------------------
今天在家用linux试了一下才发现 ,在linux下setWindowIcon这个函数是没有问题的,也就是说这个问题只有在windows下面才有,所以上面linux解决办法,当我没说。。。
相关文章推荐
- Windows XP中当最小化程序时,无法在任务栏显示图标的问题
- 解决任务栏输入法图标消失的问题
- C语言Win32 Application 的标题栏图标,任务栏图标,exe文件图标问题
- 修复Win10任务栏开始菜单等系统图标无法点击问题
- 关于点击程序的任务栏图标无法最小化程序界面的问题
- windows任务栏图标变大的问题
- vs2005下qt程序任务栏图标显示问题
- 关于C# WinForm中“显示桌面后”,点击任务栏右下角图标还原的问题 - [IT技术] 2011-
- MFC对话框初始化运行时如何隐藏,托盘图标,任务栏图标的相关问题
- 三小步解决解决火狐任务栏双图标问题
- Windows XP中当最小化程序时,无法在任务栏显示图标的问题
- Win7双击任务栏图标导致窗口还原的问题
- 解决windows7 启动MSN在任务栏显示两个图标的问题
- 解决win7任务栏音量、电源图标消失的问题
- 解决Java程序的托盘图标在Windows任务栏重建后丢失的问题(使用SystemTray类创建托盘图标)
- 任务栏的通知区域的图标模糊的问题之一
- 解决Java程序的托盘图标在Windows任务栏重建后丢失的问题(使用SystemTray类创建托盘图标)
- PyQt之自定义无边框窗口遮盖任务栏显示问题
- 小技巧教你解决任务栏图标消失问题
- Ubuntu 14.04 + gnome session back (metacity) 任务栏右上角图标消失问题解决