0

I am having issues creating a PyQt4 resources file to display images in my QGIS 2 custom feature form using Windows XP. EDIT This still gives me problems with windows 7 on 32 and 64 bit machines, so I'm pretty sure this isn't system related. Any suggestions to check if pyqt or pyrcc is installed correctly..?

These are the steps I followed:

-Added QLabel and clicked "choose resource…"

-Created my .qrc in PyQt4 designer, linked .png image file. Checked my file with notepad, and following lead of some tutorials made a few modifications (because it didn't work with the untouched resource file direct from PyQt4) My .qrc looks like this:

<!DOCTYPE RCC><RCC version ="1.0">
    <qresource prefix="/">
        <file>img/image.png</file>
    </qresource>
</RCC>

-Saved the ui and compiled the resource file in the windows command line using:

pyrcc4 -o image_rc.py image.qrc

-I even tried compiling the ui to py and moved the import space_rc to the top. I'm pretty sure this has nothing to do with the qrc file though, as it is for compiling the ui file.

pyuic4 -o form.py form.ui

then:

import image_rc

the image is called like so:

self.label_7.setPixmap(QtGui.QPixmap(_fromUtf8(":/img/image.png")))

my file system structure is like so:

ui/resource.qrc
ui/form.ui
ui/img/image.png

Under my layer's properties in QGIS, I chose to add custom ui and linked to the ui created in PyQt designer. When opening the feature form, I see only my frame, but no image. After reading many tutorials on what steps to follow, I can't see what I am missing.

I had believed it was a environment variable PATH issue (conflicting with GDAL), but now I switched computers and my issue is back. The windows environmental path for PyQt is the very first one, and I still don't see my image.

Path     C:\Python27\Lib\site-packages\PyQt4;...
  • I really hope you just have a typo in the question for the line: ... ":/img/Space.png" because your example up to that point has image.png. – Richard Morgan May 6 '15 at 21:43
  • @RichardMorgan Yeah, that's a typo. Was trying to render my stuff generic for clarity, but I missed a line. Thanks. – user25976 May 6 '15 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.