How to set image with QLabel in Qt?

后端 未结 2 2069
小鲜肉
小鲜肉 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);
    
    0 讨论(0)
  • 2020-12-09 14:08

    try following

    ui->label->setStyleSheet("background-image: url(:/1.png);");
    
    0 讨论(0)
提交回复
热议问题