resource file in PyQt4

我的未来我决定 提交于 2019-11-27 03:32:47

问题


I'm trying to understand an example in PyQt4 (simpletreemodel.pyw) I see the code

import simpletreemodel_rc

But I can't see where the module is used in the example code When I examine the module simpletreemodel, I see:

    from PyQt4 import QtCore

qt_resource_data = b"\
\x00\x00\x07\xb9\
\x47\
\x65\x74\x74\x69\x6e\x67\x20\x53\x74\x61\x72\x74\x65\x64\x09\x09\
\x09\x09\x48\x6f\x77\x20\x74\x6f\x20\x66\x61\x6d\x69\x6c\x69\x61\
\x72\x69\x7a\x65\x20\x79\x6f\x75\x72\x73\x65\x6c\x66\x20\x77\x69\
\x74\x68\x20\x51\x74\x20\x44\x65\x73\x69\x67\x6e\x65\x72\x0a\x20\
\x20\x20\x20\x4c\x61\x75\x6e\x63\x68\x69\x6e\x67\x20\x44\x65\x73\
\x69\x67\x6e\x65\x72\x09\x09\x09\x52\x75\x6e\x6e\x69\x6e\x67\x20\
\x74\x68\x65\x20\x51\x74\x20\x44\x65\x73\x69\x67\x6e\x65\x72\x20\

What this module is supposed to do? Thanks


回答1:


What you see is the byte-by-byte dump of the resources the .qrc file contains. You don't explicitly access the objects inside the module. Just import it, and you will be able to access those resources by their original names(and paths) but preceded by a colon.

pixmap = QPixMap(':/images/filename.jpg')

UPDATE: QRC file is an XML file that looks like below:

<RCC>
  <qresource prefix="/images">
    <file alias='filename.jpg'>images/filename.jpg</file>
  </qresource>
</RCC>

Then to generate it, use:

pyrcc4 -o images_rc.py images.qrc


来源:https://stackoverflow.com/questions/10951608/resource-file-in-pyqt4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!