Fit image into Qlabel
Hello dear programmers.
Well as the subject says i want to Fit my image in Qlabel but here is the case,
there is scaleContent for that Qlabel that does the Opposite job of fitting an image.
it stretches the image in both vertical and horizontal.
so any idea of how to do the trick?
i used Pixmap not QPicture:
QPixmap image(":/new/prefix1/background/main logo_.png"); ui->label->setPixmap(image); [Example of fitting an image](http://s4.img7.ir/xgUvJ.png) ```![alt text](image url)
Since you can get the size of the label, you can use QPixmap::scaled to resize the image.
Hi! If I got it right you should use this.
const int w = label->width(); const int h = label->height(); label->setPixmap(pixmap.scaled(w,h,Qt::IgnoreAspectRatio));
Final eddit ,KeepAspectRatio was the aspect ratio mode that needed for Fitting an image into Qlabel
QPixmap image("image address"); h=ui->label->height; w=ui->label->width; ui->label->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio));