Results 1 to 2 of 2

Thread: the question about setting the background picture of window?

  1. #1
    Join Date
    Aug 2007
    Posts
    1

    Default the question about setting the background picture of window?

    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
    Last edited by wmhnq; 18th August 2007 at 15:35.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: the question about setting the background picture of window?

    It might be easiest to reimplement QWidget::paintEvent() and simply stretch/center the image by hand.
    Qt Code:
    1. void MyWindow::paintEvent(QPaintEvent* event)
    2. {
    3. static QPixmap bg(":/button/Resources/1.bmp");
    4.  
    5. QPainter painter(this);
    6. // streched:
    7. painter.drawPixmap(rect(), bg, bg.rect());
    8. // or centered:
    9. // painter.drawPixmap((width() - bg.width()) / 2, (height() - bg.height()) / 2, bg);
    10. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.