PDA

View Full Version : the question about setting the background picture of window?



wmhnq
18th August 2007, 16:13
QPalette pal;
pal.setBrush(QPalette::Window,QBrush(QPixmap(":/button/Resources/1.bmp")));
this->setPalette(pal);

a question about the background picture of window ,how to set the picture extending or mediacy.
please give a example ,thank you

jpn
24th August 2007, 12:18
It might be easiest to reimplement QWidget::paintEvent() and simply stretch/center the image by hand.


void MyWindow::paintEvent(QPaintEvent* event)
{
static QPixmap bg(":/button/Resources/1.bmp");

QPainter painter(this);
// streched:
painter.drawPixmap(rect(), bg, bg.rect());
// or centered:
// painter.drawPixmap((width() - bg.width()) / 2, (height() - bg.height()) / 2, bg);
}