Reputation: 73
I would like change the QFrame Background at runtime, but, i would load the background from disk(an image). Setting stylesheet at QFrame not work's, because image isn't in resources.
One way is set a QPushButton icon, for example:
QPixmap img("/images/01.png");
ui.pushButton->setIcon(QIcon(img));
But, an QPushButton isn't useful to me. I need to put other things inside of QFrame.
Upvotes: 5
Views: 7885
Reputation: 14941
You could also try something like this:
QPalette pal;
pal.setBrush( ui.frame->backgroundRole(), QBrush( QImage( "/images/01.png" ) ) );
ui.frame->setPalette( pal );
Upvotes: 4
Reputation: 1158
From what I understood in your question, you do not want to use Resources ? If that is the case, you could do something like:
ui->frame->setFrameStyle(QFrame::StyledPanel);
ui->frame->setStyleSheet("background-image: url(C:/test.jpg)");
Upvotes: 5