Set image to label in Qt

I need to get tag image in Qt Widget

I tried to put a shortcut in the widget, and then only by its properties on the right side of the text that pixmap selected, and selected the image that I wanted to use.

however, when I run the program, no image displays any ideas, why is this?

iv also tried

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

but no luck, I don't think I used it correctly

any help would be really appreciated

+6
source share
3 answers

The official "add image to QLabel " method provided by Nokia Corp. A QPixmap .

 QLabel label; QPixmap pixmap(":/path/to/your/image.jpg"); label.setPixmap(pixmap); label.setMask(pixmap.mask()); label.show(); 
+8
source
 QIcon searchIcon = Icon::fromTheme("edit-find"); searchLabel->setPixmap( searchIcon.pixmap(16,16) ); 
0
source

Another way is to use Qt style sheets.

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

All Articles