views:

1076

answers:

2

Hello, 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.

Thanks.

A: 

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)");
nmuntz
Perfect, this is what I was looking for.I did not know that backgrounds can be applied in this way.Tkanks!
Mateu Mir
A: 

You could also try something like this:

QPalette pal;
pal.setBrush( ui.frame->backgroundRole(), QBrush( QImage( "/images/01.png" ) ) );
ui.frame->setPalette( pal );
Caleb Huitt - cjhuitt