[PyQt] Icons and Qt resources
Nahuel Defossé
nahueldefosse at yahoo.com.ar
Sun Jan 18 19:11:29 GMT 2009
El Friday 16 January 2009 06:43:46 Frédéric escribió:
> Hi,
>
> My dialogs used some icons for buttons (move left, move right...), and
> some of these buttons icons need to be changed dynamically according to
> the current sequence.
>
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.
I tend to write a Makefile to compile my qrc into python modules and also
execute pyuic on my .ui files.
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.
Nahuel
More information about the PyQt
mailing list