Results 1 to 3 of 3

Thread: Problem with background image

  1. #1
    Join Date
    Apr 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question Problem with background image

    Hi, I have a window with a Qwt barchart and I need to display a background image that fills all the window.

    The best I could get was:
    img.JPG

    As you can see, the image isn't displayed correctly. I've overridden MainWindow's resizeEvent() method this way in main.c:

    Qt Code:
    1. void MainWindow::resizeEvent(QResizeEvent*)
    2. {
    3. QPixmap bkgnd(":/files/image.png");
    4. bkgnd = bkgnd.scaled(this->size(), Qt::IgnoreAspectRatio);
    5. QPalette palette;
    6. palette.setBrush(QPalette::Background, bkgnd);
    7. this->setPalette(palette);
    8. }
    To copy to clipboard, switch view to plain text mode 

    And commented in barchart.cpp:
    Qt Code:
    1. //setAutoFillBackground( true );
    2. //setPalette( Qt::white );
    3. //canvas()->setPalette( QColor( "LemonChiffon" ) );
    To copy to clipboard, switch view to plain text mode 

    The original image is:
    image.png

    Using bkgnd = bkgnd.scaled(this->size(), Qt::KeepAspectRatioByExpanding); produces the same output.

    How can I solve it?

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem with background image

    Quote Originally Posted by qt890 View Post
    How can I solve it?
    Depends on what you want to do.

    If you really want to have the image as background of the main window you probably need to make the widgets of the plot having no background. But I would overload the paintEvent drawing the image instead of trying to set the background brush as the palette is something that is inherited by the children.

    Uwe

  3. #3
    Join Date
    Apr 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with background image

    Thanks for your reply Uwe. Yes, I want to have the image as background of the main window.

    I've tried to overload paintEvent methods this way:
    Qt Code:
    1. void BarChart::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. painter.setBackgroundMode(Qt::TransparentMode);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::paintEvent(QPaintEvent *)
    2. {
    3. QPainter painter(this);
    4. QPixmap bkgnd(":/files/image.png");
    5. painter.drawPixmap(QPoint(0,0), bkgnd);
    6. }
    To copy to clipboard, switch view to plain text mode 

    But the output is:
    img.JPG

Similar Threads

  1. background-image problem
    By zgulser in forum Newbie
    Replies: 1
    Last Post: 16th July 2012, 08:27
  2. QStackWidget background image problem
    By zgulser in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2012, 16:04
  3. Replies: 10
    Last Post: 10th November 2010, 03:12
  4. Replies: 0
    Last Post: 9th July 2010, 14:06
  5. BIG Problem with Background-image using Style Sheets
    By PiXeL16 in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:10

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.