AngryDuck
AngryDuck

Reputation: 4607

Setting an Image to a label in Qt

I need to get a label image into a Qt Widget

I have tried putting a label on the widget then just on its properties on the right under text i selected pixmap and selected the image I wanted to use.

However when I run the program no image appears any ideas why this is?

I have also tried :

QLabel label("<img src='image.jpg' />");
label.show();

But had no luck do not think I was using it right

Upvotes: 10

Views: 54735

Answers (3)

haolee
haolee

Reputation: 937

Another way is to use Qt Style Sheets.

QLabel label;
label.setStyleSheet("background-image: url(:/images/assets/your.png)")

Upvotes: 0

Erik Kaju
Erik Kaju

Reputation: 3173

Official way of "adding image to QLabel" provided by Nokia Corp. A QPixmap is used.

QLabel label;
QPixmap pixmap(":/path/to/your/image.jpg");
label.setPixmap(pixmap);
label.setMask(pixmap.mask());

label.show();

Upvotes: 16

Poul
Poul

Reputation: 3476

QIcon searchIcon = Icon::fromTheme("edit-find");
searchLabel->setPixmap( searchIcon.pixmap(16,16) );

Upvotes: 2

Related Questions