I'm developing a cross-platform application that runs both on Windows and Linux(in my case is Raspbian). I have converted all images in single file using C:\Python37\Scripts\pyside2-rcc.exe tests.qrc -o tests_rc.py
. my tests.qrc
file structure is something like this:
<RCC>
<qresource prefix="images">
<file>images/Slider_1m.png</file>
<file>images/Slider_2m.png</file>
<file>images/Slider_3m.png</file>
</qresource>
</RCC>
after converting to tests_rc.py
coded like this in the main script:
self.SLIDER.setText(QCoreApplication.translate("SLIDER",u"<html><head/><body><p align=\"center\"><img src=':/images/images/Slider_1m.png'/></p></body></html>", None))
that perfectly loaded in windows app no need to original image files anymore. But in raspbian, this kind of image wont load and I have to define location like this:
self.SLIDER.setText(QCoreApplication.translate("SLIDER",u"<html><head/><body><p align=\"center\"><img src='/home/pi/Myproject/ui/images/Slider_1m.png'/></p></body></html>", None))
As you see I set the exact image location. This is the way I have found to view in raspbian app and my tests_rc.py
file is totally useless. What should be do to use tests_rc.py
file in raspbian as same as windows?
I have mainicons.qrc
file contains:
<RCC>
<qresource prefix="images">
<file>images/calibration_.png</file>
<file>images/media_.png</file>
<file>images/menu_.png</file>
<file>images/upgrade_.png</file>
</qresource>
</RCC>
converted to mainicons_rc.py
file, then imported to this simple example:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtCore import QCoreApplication
import mainicons_rc
def window():
app = QApplication(sys.argv)
widget = QWidget()
textLabel = QLabel(widget)
textLabel.setText(QCoreApplication.translate("TestInitWindow", u"<html><head/><body><p><img src=\":/images/images/calibration_.png\"/></p></body></html>", None))
widget.setGeometry(50,50,300,300)
widget.setWindowTitle("PyQt5 Example")
widget.show()
sys.exit(app.exec_())
if __name__ == '__main__':
window()
The problem was: used to be I convert it to rcc resource file using C:\Python37\Scripts\pyside2-rcc.exe mainicons.qrc -o mainicons_rc.py
.
changing pyside-rcc.exe
to pyrcc5.exe
solved the issue, now converting command should be like: C:\Python37\Scripts\pyrcc5.exe mainicons.qrc -o mainicons_rc.py
.
I have checked both generate files are completely different.