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

不羁岁月 提交于 2019-11-29 14:07:05

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).

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