PDA

View Full Version : QPixmap and QGridLayout



Talon_Karrde
22nd February 2006, 02:43
Hi,

I'm a new Qt user and I try to a small application to display a .jpg image. But the image is never diplayed in my QLabel. I'm using a QGridLayout with Qt 4.1 and linux. Is there someone who can help me?

Here is my code:

QLabel *myimage = new QLabel();
myimage->setBackgroundRole(QPalette::Dark);
myimage->setScaledContents(true);

QPixmap pix("cylon.jpg");
myimage->setPixmap(pix);

QGridLayout *gridLayout = new QGridLayout;
gridLayout->addWidget(myimage, 0, 0);
gridLayout->addWidget(slide, 1, 0);/*a slider*/
gridLayout->addWidget(draw, 0, 1);/*a widget with a QPainter*/
gridLayout->addWidget(quit, 1, 1);/*a quit button*/
gridLayout->setColumnStretch(0, 10);
gridLayout->setColumnStretch(1, 10);
setLayout(gridLayout);

wysota
22nd February 2006, 07:29
You are using a relative path to your image. Are you sure the path is right? Check if the pixmap is valid (QPixmap::isNull).

jpn
22nd February 2006, 10:07
There is nothing wrong with the code. As you can sense from the previous post by wysota, the problem most propably derives from current path being different than where the image file is located in.

In another words, for the above code to work, the image file must be in the same directory where the application is executed from.

Talon_Karrde
22nd February 2006, 10:59
This code works great, but only when I try to debug it with GDB... If I don't use it, the label stay black... How can make it work without GDB?

(Thanks for your fast replies)

wysota
22nd February 2006, 11:35
Do you run it from the same directory where your image file resides? What happens if you change the image path to an absolute one (starting from /).

Talon_Karrde
22nd February 2006, 12:27
It works! I've change the path to a absoute path, and it works perfectly... Thanks, you saved my life!