Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
136 views
in Technique[技术] by (71.8m points)

python - resource file in PyQt4

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"
x00x00x07xb9
x47
x65x74x74x69x6ex67x20x53x74x61x72x74x65x64x09x09
x09x09x48x6fx77x20x74x6fx20x66x61x6dx69x6cx69x61
x72x69x7ax65x20x79x6fx75x72x73x65x6cx66x20x77x69
x74x68x20x51x74x20x44x65x73x69x67x6ex65x72x0ax20
x20x20x20x4cx61x75x6ex63x68x69x6ex67x20x44x65x73
x69x67x6ex65x72x09x09x09x52x75x6ex6ex69x6ex67x20
x74x68x65x20x51x74x20x44x65x73x69x67x6ex65x72x20

What this module is supposed to do? Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...