Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set background images loaded from disk

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.

like image 759
Mateu Mir Avatar asked Aug 13 '09 15:08

Mateu Mir


People also ask

How do I make a picture as a background on my Web pages?

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.


2 Answers

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)");
like image 191
nmuntz Avatar answered Oct 06 '22 06:10

nmuntz


You could also try something like this:

QPalette pal;
pal.setBrush( ui.frame->backgroundRole(), QBrush( QImage( "/images/01.png" ) ) );
ui.frame->setPalette( pal );
like image 32
Caleb Huitt - cjhuitt Avatar answered Oct 06 '22 04:10

Caleb Huitt - cjhuitt