PDA

View Full Version : setPixmap



mgurbuz
13th July 2007, 11:05
Hi All,
I'm having some trouble using the QLabel->SetPixmap
method in Windows. My application has a label and I am trying to add a pixmap on it. The pixmap is located under Resource Files picture.qrc.
The following code is the simplest example of what I'm doing:

void AModule::openRDialog()
{
QPixmap pmap(720,840);
QString iconstr = ":picture//A.png";
pmap.load(iconstr,"PNG",Qt::ColorOnly);
mDialog->ui.i90label->setPixmap(pmap);
mDialog->exec();
}

When I run the application all I could see is empty gray picture on the label.
If I put png file outside the Resources file and delete the picture.qrc
and give the new path name as

QString iconstr = "C://libraries//MODULE//A.png";

I could see the pixmap on the label. But this time,
I can't carry this exe to another machine without the png file.
How could I solve this problem? Any help will be appriciated.

jpn
13th July 2007, 11:18
Could we see the contents of .qrc file?

mgurbuz
13th July 2007, 12:34
Could we see the contents of .qrc file?

here is the picture.qrc :

<RCC>
<qresource prefix = "/picture">
<file>A.png</file>
</qresource>
</RCC>

Thank you in advance.

jpn
13th July 2007, 12:51
Try with ":/picture/A.png".

mgurbuz
13th July 2007, 13:23
Try with ":/picture/A.png".

sorry but didn't work...

thanks

jpn
13th July 2007, 13:26
Just to assure, the resource file is listed in RESOURCES variable in the .pro file?

mgurbuz
13th July 2007, 13:40
Just to assure, the resource file is listed in RESOURCES variable in the .pro file?

yes, it is listed.

guilugi
13th July 2007, 13:54
Could you provide a small sample we can test ?

pdolbey
13th July 2007, 14:21
Try with ":/picture/A.png".

That should be colon ':' not a semi-colon ';'.

Pete

p.s. QString iconstr = "C://libraries//MODULE//A.png";

should be QString iconstr = "C:\\libraries\\MODULE\\A.png"; for Windows (probably QString iconstr = "C:/libraries/MODULE/A.png"; will work with Qt). Remember that '\' is the escape character not '/'.

jpn
13th July 2007, 14:37
That should be colon ':' not a semi-colon ';'.
Hmm, italic font just makes it look like a semi-colon.