View Full Version : Image issue

Seema Rao
9th February 2006, 15:55
Hi all,

How to scale an image to a label's size and display it on the label. I tried to
do this, but even though I have scaled the pixel values of image to label size,
it is displayed partially on the label. Here is the code I have written

QLabel *mylabel = new MyLabel(mywid,"myfirstlabel");

QPixmap mypix;
mypix.load ("query.png");


mylabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);

Can some body explain how to do it?

Thanks in Advance,

9th February 2006, 16:32
Let me guess: are you trying to scale the pixmap so that it is as high as the standart label?
Try this:

// Create an empty label
QLabel *mylabel = new QLabel;
//Load the pixmap
QPixmap mypix("query.png");
//Create the instance of the default application font
QFont font;
//Create font metrics of the font
QFontMetrics metrics(font);
//Scale the pixmap to the height of the font
mypix = mypix.scaledToHeight(metrics.height());
//Set the result to the label

P.S.: Please, next time use the
and tags to make your QT code readable.

9th February 2006, 20:27
If you want the qlabel to automatically scale the pixmap for you so that it takes up all the space, all the time, then check this out:

Qt4: http://doc.trolltech.com/4.1/qlabel.html#scaledContents-prop

Qt3: http://doc.trolltech.com/3.3/qlabel.html#setScaledContents