PDA

View Full Version : fit image size to frame



saman_artorious
25th March 2013, 16:46
when the image is loaded in the frame, I need to resize frame to fit image size. Otherwise image margins may get out of frame border.
can I resize the whole image generally to fit exactly inside a frame of any size ? the image is png

^NyAw^
25th March 2013, 17:32
Hi,

Take a look at QImage::scaled

saman_artorious
26th March 2013, 04:57
Hi,

Take a look at QImage::scaled

I used scaled() to resize the image, but it has no effect!



QImage myImage;
myImage.load("path-to-png");
myImage.scaled(ui->frame->width(), ui->frame->height(), Qt::IgnoreAspectRatio );
ui->frame->setPixmap(QPixmap::fromImage(myImage));


is there anything wrong with the code?

^NyAw^
26th March 2013, 08:45
Hi,



is there anything wrong with the code?

Yes.
It's a programming error. Have you looked what the method does? Or what it says that does?

Returns a copy of the image scaled to a rectangle with the given width and height according to the given aspectRatioMode and transformMode.

saman_artorious
26th March 2013, 09:15
;) thanks for the hint. :D