[PyQt] Icons and Qt resources

Frédéric frederic.mantegazza at gbiloba.org
Sun Jan 18 19:24:08 GMT 2009


On dimanche 18 janvier 2009, Nahuel Defossé wrote:

> They are very easy to use. Just create a qrc file, which is basically
> something like this:
> <!DOCTYPE RCC><RCC version="1.0">
> <qresource prefix="/">
>         <file>coolicons/cubic.svg</file>
> </qresource>
> <qresource prefix="/small">
>         <file>smallicons/cubic.png</file>
> </qresource>
> </RCC>
>
> Once you've compiled the module with pyrcc4, then import the module
> somewhere in your code.
> Then use them like this
> my_image = QPixmap(":/coolicons/cubic.svg") # Or
> :/small/smallicons/cubic.png my_button_dialog.setPixmap( my_image )
>
> Take into account that you should use : <PREFIX> / <PATH>.
>
> Qrc files can be created and used by designer, which is very handy, but
> you can create your own.

Ok, I got it!

> I tend to write a Makefile to compile my qrc into python modules and
> also execute pyuic on my .ui files.

Good idea. I'll do that too (even if I dont compile .ui files, but using 
uic module to dynamically load the GUI; but that's a question I plan to 
ask).

> SVG is nice, but if you product target is windows, I'd stick to PNG.
> I've had some issues, specially setting top level window icons with SVG,
> and sometimes Inkscape generated svg files throw some debug info (like
> gradients not understood) when Qt loads them.

Ok, thanks for the tip.

-- 
    Frédéric

    http://www.gbiloba.org



More information about the PyQt mailing list