[PyQt] Absolute paths in qrc file.

Baz Walter bazwal at ftml.net
Fri Jun 28 17:08:40 BST 2013


On 28/06/13 15:45, Eric Frederich wrote:
> I'm having trouble working with absolute file paths in my qrc resource
> file with PyQt.
> Am I doing something wrong or is it just something that rcc happens to
> support but not pyrcc4?
>
> Here is my resource file
>
>      $ cat resources.qrc
>      <!DOCTYPE RCC><RCC version="1.0">
>      <qresource>
>      <file alias="filesaveas.png">/usr/share/icons/oxygen/32x32/actions/document-save-as.png</file>
>      </qresource>
>      </RCC>
>
> When I invoke pyrcc4:
>
>      $ pyrcc4 -o qrc_resources.py resources.qrc
>      Cannot find file: /usr/share/icons/oxygen/32x32/actions/document-save-as.png
>      No resources in resource description.
>
> The file does exist:
>
>      $ file /usr/share/icons/oxygen/32x32/actions/document-save-as.png
>      /usr/share/icons/oxygen/32x32/actions/document-save-as.png: PNG
> image data, 32 x 32, 8-bit/color RGBA, non-interlaced
>
> Note: rcc works fine with this file:
>
>      $ rcc resources.qrc -o resources.rcc
>      $ wc -l resources.rcc
>      199 resources.rcc

Don't know about rcc, but the Qt docs are pretty clear that relative 
paths must be used in qrc files:

 
https://qt-project.org/doc/qt-4.8/resources.html#resource-collection-files

I suppose you could just use a symlink to work around this.

PS: For standard icons, a possible alternative solution is to use 
QIcon.fromTheme (only really useful on Linux, though):

     https://qt-project.org/doc/qt-4.8/qicon.html#fromTheme

-- 
Regards
Baz Walter


More information about the PyQt mailing list