PDA

View Full Version : Best way to "include" the images of an application



SkripT
18th April 2006, 17:20
Hi all, I don't have much experience creating GUI applications and I would like to know what's the best/cleaner/common way to include the images (button icons, background images, etc) that the applications uses. I've thought in various solutions: placing all in a specified directory inside the app directory, including them in the executable,... Could you suggest me something? Thanks.

ChMaster
18th April 2006, 17:40
hi,

use the resource system from Qt4, i mean put all picture in one directory or so and
create an qrc file like: application.qrc.

open the file and enter the follow lines:



<RCC>
<qresource prefix="/pic" >
<file>picture1.png</file>
</qresource>
</RCC>


save and close. open the pro file and add this line:
RESOURCES += application.qrc

you can use it as example:


tBtn = new QToolButton( "nothing to have :)" );
tBtn->setIcon( QPixmap( ":/pic/picture1.png" ) );


i hope this help you :)

Chicken Blood Machine
18th April 2006, 17:43
Hi all, I don't have much experience creating GUI applications and I would like to know what's the best/cleaner/common way to include the images (button icons, background images, etc) that the applications uses. I've thought in various solutions: placing all in a specified directory inside the app directory, including them in the executable,... Could you suggest me something? Thanks.

It's up to you. I prefer to embed them in the executable, because:

a) Overall, your distribution will take up less space than if it contains a folder of separate image files.
b) The images should load slightly faster, since they are already in memory.
c) The integrity of the images in your program is not compromised - users cannot change them, delete them etc.

You can use the Qt resource system to do this.

However, if you are not fussy about the size of your package (no pun intended) and you would like to allow users to customize the images in your app (a basic form of skinning) then feel free to place them in a separate images directory.

SkripT
18th April 2006, 18:14
Thanks a lot both. These posts have been very helpful :)

Chicken Blood Machine
18th April 2006, 18:32
Thanks a lot both. These posts have been very helpful :)

EDIT: I still have a little question: Will the method commented by ChMaster integrate the images in the executable file using the resource file?

Yes it will.