PyQt/PySide - 图标显示
我有一个 PySide 应用程序,其中有一个 MainWindow 图标(一个 QMainWindow 实例)。当我正常运行文件时,图标是可见的,一切都很好,但是当我使用 py2exe 创建 exe 时,图标不出现。 cx_freeze
也会发生这种情况(所以我认为问题不在于 py2exe
)。
该应用程序是使用 QtDesigner
设计的,并使用 pyside-uic
转换为 python。我尝试使用图标作为文件和资源(qrc 文件),但两者似乎都不起作用。
任何帮助或指示将不胜感激。
谢谢。
I have a PySide app which has an icon for the MainWindow
(a QMainWindow
instance). When I run the file normally, the icon is visible and everything is fine but when I create an exe with py2exe
, the icon does not appear. This happens with cx_freeze
also( so I don't think the problem's with py2exe
).
The app was designed using QtDesigner
and converted to python with pyside-uic
. I tried both using icons as a file and as a resource(qrc file) and both don't seem to work.
Any help or pointers would be appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只要您不尝试将 Qt dll 捆绑到library.zip 或exe 中,kochelmonster 的解决方案就可以工作。如果将插件放在应用程序目录的根目录中,则也不需要设置库路径。
我仍然想捆绑其他所有内容,因此我排除了 qt dll 并手动添加它们。我的 setup.py 看起来像这样:
如果您的项目使用其他 Qt dll,您还必须排除并手动添加它们。如果您需要加载 .ico 图像以外的其他内容,您还需要添加正确的插件。
kochelmonster's solution works so long as you don't try and bundle the Qt dlls into library.zip or the exe. You also don't need to set a library path if you put the plugins in the base of the app directory.
I still wanted to bundle everything else so I excluded the qt dlls and added them manually. My setup.py looks something like this:
If your project uses additional Qt dlls you will have to exclude and manually add them as well. If you need to load something other than an .ico image you'll also need to add the correct plugin.
我假设它适用于 bmp,但不适用于 png/jpg?如果是这样,图像格式插件可能无法正确加载。
我猜想在安装的应用程序目录中设置一个 qt.conf 文件,确保插件 dll 转到 /plugins/imageformats/ 将使事情工作得更好。
I'm assuming it works with a bmp, but not a png/jpg? If so, it's likely that the image format plugins don't load properly.
I'd guess setting up a qt.conf file in the installed application's directory and making sure plugin-dll's go to /plugins/imageformats/ will make things work better.
我也有同样的问题。经过一番调查我找到了解决方案:
(Macke 的想法是正确的)
cx_freeze
不会复制PyQt
插件目录,其中包含ico
图像阅读器。步骤如下:
setup.py
中将PyQt4
插件目录复制到您的发行版中,I had the same problem. After some investigation I found a solution:
(Macke had the right idea)
cx_freeze
does not copy thePyQt
plugins directory, which contains theico
image reader.Here are the steps:
setup.py
copy thePyQt4
plugins directory to your distribution是否与 Windows 7 的任务栏图标处理有关?
有关答案,请参阅如何在 Windows 7 中设置应用程序的任务栏图标。
Could it be related to Windows 7's taskbar icon handling?
See How to set application's taskbar icon in Windows 7 for an answer to that.
您必须在发布文件夹中手动包含“qico4.dll”。将其插入到 setup.py 中:
You must include "qico4.dll" manually in your release folder. Insert this in your setup.py: