Issue
I have this estructure on my application:
|-App
|
|-functions
|
|-ui
|--ui.py
|
|images
|
|main.py
i have a functions folder with some scripts and a ui folder with the PyQt generated code on the ui.py file.
and a main.py file that loads the ui.py to show the interface and ui.py loads some images from the "images" folder on the root.
if I execute my script directly on python (double clic on main.py file), the images wont show..
But if I use the terminal with "python main.py" the images show correctly.
The references on ui.py are like:
icon.addPixmap(QtGui.QPixmap(_fromUtf8("images/flags/MXN.png"))
Solution
Use the Qt Designer Resource System to create a resource file for the images.
Then use PyQt's pyrcc tool to convert the Qt resource file into a python module.
NB: The python resource module should go in the same directory as your ui files. So if you created the resource file App/resources.qrc
in Qt Designer, you should then convert it like this:
pyrcc5 -o App/ui/resources_rc.py App/resources.qrc
The equivalent tool for PySide (Qt4) was pyside-rcc
. For PySide2/PySide6, the Qt rcc
tool itself has an option to produce python output:
rcc -g python -o App/ui/resources_rc.py App/resources.qrc
UPDATE:
PyQt6 has now removed the pyrcc tool (see: How can resources be provided in PyQt6 (which has no pyrcc)?).
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.