PDA

View Full Version : how do load image



yuvaraj.yadav
20th April 2009, 14:04
hi

i am newbee to Qt


How do upload the image for project....


please provide me sample code


Thanks

Yuvaraj R

graciano
20th April 2009, 14:22
Try this one example (http://gracianotorrao.wordpress.com/?s=jogo+do+galo) i'm still working on.
You must be talking about the qrc file (resource) and loading the png images to an object (QPushButton in the example) ... something like that?!

yuvaraj.yadav
20th April 2009, 14:26
Thanks for your reply...


i am beginner .....I don't know in deapth


So give the sample code to upload image from my system



Thanks

Yuvaraj R

graciano
20th April 2009, 14:36
QPixmap Sender::selectImg(int i){
QPixmap image;
switch (i){
case 0: image.load(":/quatroestacoes/primavera");
break;
case 1: image.load(":/quatroestacoes/verao");
break;
case 2: image.load(":/quatroestacoes/outono");
break;
case 3: image.load(":/quatroestacoes/inverno");
break;
case 4: image.load(":/quatroestacoes/as4estacoes");
}
return image;
}

In this function i select an imagem, load it into a QPixmap object, and the return it to the call point.

You must replace ...

image.load(":/quatroestacoes/as4estacoes");
... by something like ...

image.load("yourpath/imagename.png");
... if you have not created the resource file.
...but there are many other ways to do it :)

graciano
20th April 2009, 14:41
Here is a simple one:

ui->receiverLight->setPixmap(QPixmap("imagens/off.png"));
Where:

receiverLight is a QLabel object
the file name of the image is off.png

aamer4yu
21st April 2009, 05:31
Dont you have access to Qt Demos ? It is a very good place to start with.
You will get almost every example you need for a beginner .