繁体   English   中英

PyQt 应用程序 rcc 转换后的图像在 raspbian(Raspberry Pi OS)中找不到

[英]PyQt application rcc converted image not found in raspbian (Raspberry Pi OS)

我正在开发一个在 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文件?

我有mainicons.qrc文件包含:

<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>

转换为mainicons_rc.py文件,然后导入到这个简单的例子中:

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()

问题是:曾经是我使用C:\Python37\Scripts\pyside2-rcc.exe mainicons.qrc -o mainicons_rc.py将其转换为 rcc 资源文件。 pyside-rcc.exe更改为pyrcc5.exe解决了这个问题,现在转换命令应该是: C:\Python37\Scripts\pyrcc5.exe mainicons.qrc -o mainicons_rc.py 我检查了两个生成文件完全不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM