How to install image from QLabel in Qt?

ui->label->setStyelSheet("image:url(:/1.png); border-image:url(:/2.png);"); 

Why is the image not displayed after startup? But the image border of the image is normal.
It may display fine in Qtcreator. It can display the image in the compiler without even starting.

+4
source share
2 answers

I think that the image property is used only for subcontrol (see doc ), and border-image is used for labels. Use

  QPixmap::QPixmap ( const QString & fileName, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor ); QLabel::setPixmap ( const QPixmap & ); 

Like this:

 QPixmap pix(":/1.png"); ui->label->setStyleSheet("border-image:url(:/2.png);"); ui->label->setPixmap(pix); 
+5
source

try to execute

 ui->label->setStyleSheet("background-image: url(:/1.png);"); 
0
source

All Articles