PyQt/PySide - 图标显示 [英] PyQt/PySide - icon display

查看:37
本文介绍了PyQt/PySide - 图标显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PySide 应用程序,它有一个 MainWindow 图标(一个 QMainWindow 实例).当我正常运行文件时,图标是可见的,一切都很好,但是当我用 py2exe 创建一个 exe 时,图标没有出现.这也发生在 cx_freeze 上(所以我认为问题不在于 py2exe).

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

该应用程序是使用 QtDesigner 设计的,并使用 pyside-uic 转换为 python.我尝试将图标用作文件和资源(qrc 文件),但似乎都不起作用.

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.

谢谢.

推荐答案

kochelmonster 的解决方案只要您不尝试将 Qt dll 捆绑到 library.zip 或 exe 中即可.如果您将插件放在应用程序目录的根目录中,您也不需要设置库路径.

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.

我仍然想捆绑所有其他东西,所以我排除了 qt dll 并手动添加了它们.我的 setup.py 看起来像这样:

I still wanted to bundle everything else so I excluded the qt dlls and added them manually. My setup.py looks something like this:

from os.path import join

_PYSIDEDIR = r'C:\Python27\Lib\site-packages\PySide'
data_files =[('imageformats',[join(_PYSIDEDIR,'plugins\imageformats\qico4.dll')]),
              ('.',[join(_PYSIDEDIR,'shiboken-python2.7.dll'),
                join(_PYSIDEDIR,'QtCore4.dll'),
                join(_PYSIDEDIR,'QtGui4.dll')])
              ]
setup(
    data_files=data_files,
    options={
        "py2exe":{
            "dll_excludes":['shiboken-python2.7.dll','QtCore4.dll','QtGui4.dll'],
            "bundle_files": 2
            ...
        }
    }
    ...
)

如果您的项目使用额外的 Qt dll,您也必须排除并手动添加它们.如果您需要加载 .ico 图片以外的内容,您还需要添加正确的插件.

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.

这篇关于PyQt/PySide - 图标显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆