Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an Image to a label in Qt

Tags:

image

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

like image 332
AngryDuck Avatar asked Apr 15 '13 10:04

AngryDuck


People also ask

How do I add an image to a label in Qt?

Using Qt Designer Next, with the Label selected, look in the right hand QLabel properties panel for the pixmap property (scroll down to the blue region). From the property editor dropdown select "Choose File…" and select an image file to insert.

What is label in Qt?

QLabel is used for displaying text or an image. No user interaction functionality is provided. The visual appearance of the label can be configured in various ways, and it can be used for specifying a focus mnemonic key for another widget.


2 Answers

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();
like image 115
Erik Kaju Avatar answered Oct 20 '22 19:10

Erik Kaju


QIcon searchIcon = Icon::fromTheme("edit-find");
searchLabel->setPixmap( searchIcon.pixmap(16,16) );
like image 21
Poul Avatar answered Oct 20 '22 21:10

Poul