【发布时间】:2021-01-18 14:27:02
【问题描述】:
我正在开发一个在 Windows 和 Linux 上运行的跨平台应用程序(在我的例子中是 Raspbian)。我已使用 C:\Python37\Scripts\pyside2-rcc.exe tests.qrc -o tests_rc.py 将所有图像转换为单个文件。我的tests.qrc 文件结构是这样的:
<RCC>
<qresource prefix="images">
<file>images/Slider_1m.png</file>
<file>images/Slider_2m.png</file>
<file>images/Slider_3m.png</file>
</qresource>
</RCC>
在主脚本中转换为tests_rc.py 后编码如下:
self.SLIDER.setText(QCoreApplication.translate("SLIDER",u"<html><head/><body><p align=\"center\"><img src=':/images/images/Slider_1m.png'/></p></body></html>", None))
在 Windows 应用程序中完美加载不再需要原始图像文件。 但是在 raspbian 中,这种图像不会加载,我必须像这样定义位置:
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))
如您所见,我设置了确切的图像位置。这是我发现在 raspbian 应用程序中查看的方式,而我的 tests_rc.py 文件完全没用。在raspbian中和windows一样使用tests_rc.py文件应该怎么做?
【问题讨论】:
-
其他资源文件能用吗?您是否完全确定您在两个操作系统中使用了相同的资源文件并且您正确地导入了它?
-
我有 3 个像这样的各种资源文件,并且在 Windows 中都可以正常工作,我检查文件并替换了 100 多次,我正在 Windows 中编写代码并转移到 Rasp
-
@MohammadFarahi 请提供minimal reproducible example
标签: python qt raspberry-pi pyqt5 raspbian