How to load .ico files in PyQt4 from network

2019-02-18 17:27发布

问题:

I have a app developed in PyQt4.

It has icons set for windows and QMenus.

All client systems have installed python. And PyQt4 is loaded from network location (\\system_xyz\PyQt4).

The app works fine in developer systems with icons loaded properly. But when the same script is run on clients, app works but icons are not loaded.

In my app i used Qsql drivers also. It too had the same issue. works at developer system but not at client system.

I could able to overcome this sql driver issue by adding sql plugin path to the app like below

SQLDriverPath = (r'\\system_xyz\PyQt4\plugins\sqldrivers')
QtGui.QApplication.addLibraryPath(SQLDriverPath)

I came to understand that pyqt4 needs qico4.dll to read .ico files. so i added the imageformats path to the app. but it did not work.

ImageDriverPath = (r'\\system_xyz\PyQt4\plugins\imageformats')
QtGui.QApplication.addLibraryPath(ImageDriverPath)

Can any one suggest me a correct approach to solve my issue loading .ico in PyQt app from network

MY UPDATES

i did following to list the supported image formats.

import sys

sys.path.append(r'r'\\system_xyz')

from PyQt4 import QtGui

for imageType in QtGui.QImageReader.supportedImageFormats():
    print imageType

OUTPUT

bmp
pbm
pgm
png
ppm
xbm
xpm

I tried to list as above after adding imageformats, The OP is the same even tried after creating QtGui,QApplication(). Same result no change.

回答1:

You can set the paths in qt.conf file and place this file in the location of your executable file of your application.

Accessing PyQt4 from Network Location say \somesystem\Share\PyQt4

you can find a qt.conf file in \\somesystem\Share\PyQt4 copy it and paste the .conf file in the location of your executable file of your application.

edit the below lines in qt.conf

[Paths]
Prefix = //somesystem/Share/PyQt4
Binaries = //somesystem/Share/PyQt4

Everything works fine, even sqldrivers will be loaded. No Need of using app.addLibraryPath You can also include this file in your setup so that it will be automatically installed.



回答2:

Although answer is being accepted, here is a better solution for network PyQt4 plugin loading.

After checking official addLibraryPath pages, I found that you have to use QtCore.QCoreApplication.addLibraryPath(). So instead of using QtGui version, use like following:

QtCore.QCoreApplication.addLibraryPath( '//server/location/PyQt4/plugins' )
app = QtGui.QApplication(sys.argv)

If you do this right before you create your QApplication, you will be set. I don't even need to use qt.conf at all to load plugins properly from my network drive.



标签: path icons pyqt4