13

Looking through the widgets supplied by Qt, it seems there isn't one for displaying images. What is the proper way to display an image in Qt?

dbryan
  • 153
  • 1
  • 2
  • 5
  • 1
    take a look at [Stackoverflow question 1357960](https://stackoverflow.com/questions/1357960/qt-jpg-image-display) – yass Jun 26 '17 at 20:34
  • 4
    Possible duplicate of [Qt jpg image display](https://stackoverflow.com/questions/1357960/qt-jpg-image-display) – KjMag Jun 26 '17 at 20:53

1 Answers1

21

There isn't a widget specifically made for displaying images, but this can be done with the label widget. We do this with the pixmap property.

In your code, make sure you include

#include <QPixmap>

Then, wherever you wish to set the image, include the following

QPixmap pic("/path/to/your/image");
ui->label->setPixmap(pic);

What we do here is create a QPixmap object, which serves as an image, and then set that object to the pixmap property of the label.

Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48
Joe Broder
  • 326
  • 2
  • 5