How to set image with QLabel in Qt?

后端 未结 2 2077
小鲜肉
小鲜肉 2020-12-09 13:31
ui->label->setStyelSheet(\"image:url(:/1.png); border-image:url(:/2.png);\");  

Why can\'t the image be displayed after run? But the border-i

2条回答
  •  感动是毒
    2020-12-09 14:00

    I think the image property is for subcontrol only (see doc ), while border-image is valid 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);
    

提交回复
热议问题