PyQt/PySide - 图标显示

发布于 2024-10-10 02:33:07 字数 333 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

勿挽旧人 2024-10-17 02:33:07

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

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

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 图像以外的其他内容,您还需要添加正确的插件。

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:

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

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.

土豪我们做朋友吧 2024-10-17 02:33:07

我假设它适用于 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.

囚你心 2024-10-17 02:33:07

我也有同样的问题。经过一番调查我找到了解决方案:
(Macke 的想法是正确的)

cx_freeze 不会复制 PyQt 插件目录,其中包含 ico 图像阅读器。
步骤如下:

  1. setup.py 中将 PyQt4 插件目录复制到您的发行版中,
  2. 在代码中编写如下内容:
application_path = os.path.split(os.path.abspath(sys.argv[0]))[0]
尝试:
   如果系统冻结:
        plugin_path = os.path.join(application_path, "qtplugins")
        app.addLibraryPath(plugin_path)
除了属性错误:
    经过

I had the same problem. After some investigation I found a solution:
(Macke had the right idea)

cx_freeze does not copy the PyQt plugins directory, which contains the ico image reader.
Here are the steps:

  1. in setup.py copy the PyQt4 plugins directory to your distribution
  2. In your code write something like:
application_path = os.path.split(os.path.abspath(sys.argv[0]))[0]
try:
   if sys.frozen:
        plugin_path = os.path.join(application_path, "qtplugins")
        app.addLibraryPath(plugin_path)
except AttributeError:
    pass
拧巴小姐 2024-10-17 02:33:07

是否与 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.

找个人就嫁了吧 2024-10-17 02:33:07

您必须在发布文件夹中手动包含“qico4.dll”。将其插入到 setup.py 中:

import sys
from os.path import join, dirname
from cx_Freeze import setup, Executable

_ICO_DLL = join(dirname(sys.executable), 
                     'Lib', 'site-packages',
                     'PySide', 'plugins',
                     'imageformats', 'qico4.dll')

build_exe = {
        'include_files': [(
                _ICO_DLL,
                join('imageformats', 'qico4.dll'))]}

setup(name = "xxxxx",
      version = "1.0.0",
      ...
      options = { ...
                 'build_exe': build_exe
                  ...},
      ...)

You must include "qico4.dll" manually in your release folder. Insert this in your setup.py:

import sys
from os.path import join, dirname
from cx_Freeze import setup, Executable

_ICO_DLL = join(dirname(sys.executable), 
                     'Lib', 'site-packages',
                     'PySide', 'plugins',
                     'imageformats', 'qico4.dll')

build_exe = {
        'include_files': [(
                _ICO_DLL,
                join('imageformats', 'qico4.dll'))]}

setup(name = "xxxxx",
      version = "1.0.0",
      ...
      options = { ...
                 'build_exe': build_exe
                  ...},
      ...)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文