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