Set background image in QMainWindow
hi,
I have a problem when i try to load a background image in a QMainWindow.
i override the paintevent method with the next code:
Code:
{
pPainter
->drawPixmap
(rect
(),
QPixmap(":/images/metal.png"));
delete pPainter;
}
I think the code is ok, but i am not sure!!! It doesnt load any bg image.
the image size has to match with mainwindow size?
any ideas??
thank you.
Re: Set background image in QMainWindow
I think the following line of code is drawing on top of your image and that is why you are not able to see the image
Remove the following line, make sure that the image file is part of your resources and then try.
Re: Set background image in QMainWindow
pPainter->drawPixmap(rect(), QPixmap(":/images/metal.png"));
Maybe you should change this line to
pPainter->drawPixmap(rect(), QPixmap("./images/metal.png"));
Re: Set background image in QMainWindow
Instead of overriding the main window, you can set the background through palette
QPalette::setBrush with QPalette::Window.
And I hope you you know how to make brush of pixmap :)
Re: Set background image in QMainWindow
using palette for setting background
Code:
QPixmap pixmap
("jughead-jones_large.png");
w.setPalette(p);
w.resize(pixmap.size())