Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display an image with Qt

Tags:

c++

image

widget

qt

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?

like image 384
dbryan Avatar asked Jun 26 '17 20:06

dbryan


1 Answers

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.

like image 113
Joe Broder Avatar answered Nov 05 '22 06:11

Joe Broder