Answer the question
In order to leave comments, you need to log in
Display file.jpg background on QWidget?
#include<QtWidgets>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget wgt;
wgt.resize(500,500);
QWidget* w1 = new QWidget(&wgt);
QPalette pal1;
pal1.setColor(w1->backgroundRole(),Qt::black);
w1->setPalette(pal1);
w1->setGeometry(50,50,100,100);
w1->setAutoFillBackground(true);
QWidget* w2 =new QWidget(&wgt);
QPalette pal2;
pal2.setBrush(w2->backgroundRole(),QBrush(QPixmap(":/HappyB003.jpg")));
w2->setPalette(pal2);
w2->setGeometry(0,200,100,100);
w2->setAutoFillBackground(true);
wgt.show();
return a.exec();
}
Answer the question
In order to leave comments, you need to log in
Try like this
Well, or put the image in QLabel::setPixmap, then manage the geometry manually.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question