A .py file which compiled from .qrc file( using pyside-rcc ) does not work
Asked Answered
U

1

5

I am working on python project and I have a problem with my .py file which complied from .qrc file. First, let I explain briefly about my project.

I created my project GUI in QtDesigner and also use the image in the GUI. Then, I generate .py from .ui file using pyside-uic and generate .py file from .qrc file using pyside-rcc. The problem is when I use the .py file (an image file), images does not show in my GUI.

Is anybody knows how to solve this problem?

Thank you for all your answer. :)

Ps. I use PySide as my GUI language.

United answered 19/3, 2014 at 14:8 Comment(1)
Can u supply simple summary about your code and qrc file ?Trigeminal
W
7

Have you actually added the resource to your GUI project?

Starting from scratch, here's how to do it:

In Qt Designer, select View > Resource Browser. Then, in the Resource Browser, click the Edit Resources button. From there, you can either create a new resouce file, or open an existing one. The important thing is that the resource file must be able to access the resources (e.g. image files) using relative paths. So that means they must be either in the same directory as the resource file, or one of its sub-directories.

Once you've created the resource file, add a prefix (e.g. "images") using the buttons below the right-hand pane, then add your images (or whatever), and finally click Ok.

Now when you want to add a pixmap to a label, just make sure you select the image from your new resource, rather than the file on disk.

The final steps are to re-generate your GUI module using pyside-uic and generate the resources module using pyside-rcc. When you do this, make sure the resources module is saved as "resource_rc.py" in the same directory as the GUI module:

    pyside-uic -o widget.py widget.ui
    pyside-rcc -o resource_rc.py resource.qrc

(PS: if your are using packages in your project, you should use the --from-imports option with pyside-uic to get relative imports).

Wirework answered 19/3, 2014 at 20:56 Comment(3)
I followed these steps exactly but pyside-rcc results in dyld: Library not loaded: @rpath/lib/QtCore.framework/Versions/4/QtCore Referenced from: /Users/jmason86/Library/Enthought/Canopy_64bit/User/bin/pyside-rcc Reason: image not found Abort trap: 6 Everything is in a single directory together. I've also tried moving the image into a subdirectory called images with everything else the same. No dice.Arcadian
@JamesPMason. Your problem has got nothing to do with the instructions which I gave. There is obviously something wrong with your pyside installation (but I don't know exactly what).Wirework
You're right! These instructions worked perfectly once I did this really weird fix: #28481402Arcadian

© 2022 - 2024 — McMap. All rights reserved.