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.
To set the background image of a webpage, use the CSS style. Under the CSS <style> tag, add the property background-image. The property sets a graphic such as jpg, png, svg, gif, etc. HTML5 do not support the <body> background attribute, so CSS is used to change set background image.
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)");
You could also try something like this:
QPalette pal;
pal.setBrush( ui.frame->backgroundRole(), QBrush( QImage( "/images/01.png" ) ) );
ui.frame->setPalette( pal );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With