Results 1 to 3 of 3

Thread: QGraphicsView setBackgroundBrush problem

  1. #1
    Join Date
    Sep 2010
    Location
    Tampere, FINLAND
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default QGraphicsView setBackgroundBrush problem

    Hi,
    I'm stuck when trying to set background image to my graphicsview.
    Graphicsview is part of my ui. I have tested basicly the same without using ui-file and it worked, but this isn't. Below my code, what I'm missing?
    Qt Code:
    1. QPixmap bgPix(":/Time-For-Lunch-2.jpg");
    2. ui->GraphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    3. ui->GraphicsView->setBackgroundBrush(QBrush(bgPix));
    4. ui->GraphicsView->setCacheMode(QGraphicsView::CacheBackground);
    5. ui->GraphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
    6. ui->GraphicsView->show();
    To copy to clipboard, switch view to plain text mode 

    I also have tried to create scene and setBackground to it, then setting the scene to view. Didn't work

    Thanks

  2. #2
    Join Date
    Sep 2010
    Location
    Tampere, FINLAND
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: QGraphicsView setBackgroundBrush problem

    And the magic happens when you post it to public aka problem solved.

    Seems that if you dont give scene, which is member variable, ui will lost it. Or something like that

  3. The following user says thank you to kapseli for this useful post:

    szisziszilvi (1st March 2011)

  4. #3
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView setBackgroundBrush problem

    yeah, thank's, I've almost posted a new thread! For others joy:
    I gave a private member to the declaration of MainWindow: QGraphicsScene sc;
    then into the constructor:
    QPixmap qpxm;
    qpxm.load(myImagePath));
    sc.setBackgroundBrush(QBrush(qpxm));
    ui->graphicsView->setScene(&sc);
    hope I'll be able to position and streach it soon.

Similar Threads

  1. setBackgroundBrush Question
    By qtuser20 in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2009, 13:22
  2. QGraphicsView Problem
    By Toaders in forum Newbie
    Replies: 1
    Last Post: 15th May 2009, 18:48
  3. QGraphicsView Problem
    By hakkman in forum Qt Programming
    Replies: 2
    Last Post: 14th June 2008, 20:27
  4. QGraphicsView Problem !!
    By Gamalof in forum Qt Programming
    Replies: 3
    Last Post: 14th June 2008, 13:55
  5. Problem with QGraphicsView.
    By kiranraj in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2007, 19:44

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.