PDA

View Full Version : Image issue



Seema Rao
9th February 2006, 14: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");
mylabel->setGeometry(0,6,100,100);

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

mypix.scaledToWidth(100,Qt::FastTransformation);
mypix.scaledToHeight(100,Qt::FastTransformation);

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

Can some body explain how to do it?

Thanks in Advance,
Seema

Cesar
9th February 2006, 15: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
mylabel->setPixmap(mypix);


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

alu
9th February 2006, 19: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