Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt/PySide - icon display

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.

like image 955
user547057 Avatar asked Jan 01 '11 12:01

user547057


People also ask

Should I use PySide or PyQt?

Advantages of PySide PySide represents the official set of Python bindings backed up by the Qt Company. PySide comes with a license under the LGPL, meaning it is simpler to incorporate into commercial projects when compared with PyQt. It allows the programmer to use QtQuick or QML to establish the user interface.

How do I add an icon to QT?

This can be done using Microsoft Visual Studio: Select File >> New, and choose the Icon File. Note: You need not load the application into the Visual Studio IDE as you are using the icon editor only. Store the ICO file in your application's source code directory, for example, with the name appico.

Does Qt have built in icons?

Qt ships with a small set of standard icons you can use in any of your applications for common actions. The icons are all accessible through the current active application style -- available as a series of flags, which can be passed to .

What is QT PySide?

PySide is a Python binding of the cross-platform GUI toolkit Qt developed by The Qt Company, as part of the Qt for Python project. It is one of the alternatives to the standard library package Tkinter. Like Qt, PySide is free software.


2 Answers

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.

like image 179
Gerald Avatar answered Sep 28 '22 06:09

Gerald


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.

like image 28
Macke Avatar answered Sep 28 '22 06:09

Macke