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?
Asked
Active
Viewed 2.3k times
13
-
1take a look at [Stackoverflow question 1357960](https://stackoverflow.com/questions/1357960/qt-jpg-image-display) – yass Jun 26 '17 at 20:34
-
4Possible duplicate of [Qt jpg image display](https://stackoverflow.com/questions/1357960/qt-jpg-image-display) – KjMag Jun 26 '17 at 20:53
1 Answers
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
-
4`QGraphicsView` has much more possibilities if one want such (scroll bars, rotation, etc). – Mariusz Jaskółka Jun 27 '17 at 13:09