Setting background images downloaded from disk

I would like to change the background of the QFrame at runtime, but I would load the background from disk (image). Setting a stylesheet in a QFrame does not work because the image is not in resources.

In one of the methods, the QPushButton icon is set, for example:

QPixmap img("/images/01.png");
ui.pushButton->setIcon(QIcon(img));

But QPushButton is not useful to me. I need to put other things inside a QFrame.

+5
source share
2 answers

From what I understood in your question, you do not want to use resources? If so, you can do something like:

ui->frame->setFrameStyle(QFrame::StyledPanel);
ui->frame->setStyleSheet("background-image: url(C:/test.jpg)");
+5
source

You can also try something like this:

QPalette pal;
pal.setBrush( ui.frame->backgroundRole(), QBrush( QImage( "/images/01.png" ) ) );
ui.frame->setPalette( pal );
+4
source

All Articles