0

I know how to view a image in the full window from Qt jpg image display but I need to display the image 200x300px size. that means I need the program to read the jpg image and rezise it and view it in a small box placed in the side of the window. I dont have eny idea which widget I should place for this and the method to do this. can somebody point out me some tutorial or give in simple advice.

thank you.

Community
  • 1
  • 1
danial weaber
  • 846
  • 2
  • 17
  • 37

1 Answers1

3

After you load the image, for example:

QImage img;
img.loadFromData(data);

use QImage::scaled() to create a scaled copy of it and assign it to itself. Example:

img = img.scaled(200, 300, Qt::KeepAspectRatio, Qt::SmoothTransformation);

Adjust the flags as preferred (see the QImage::scaled() documentation on the available flags.)

You can then display it. The easiest way is to set it as a pixmap on a QLabel:

QLabel label;
label.setPixmap(QPixmap::fromImage(img));

You might want to set a fixed size for the QLabel, but this depends on how you handle your overall layout in your application.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96