PDA

View Full Version : QGraphicsView setBackgroundBrush problem



kapseli
25th September 2010, 00:04
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?

QPixmap bgPix(":/Time-For-Lunch-2.jpg");
ui->GraphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectV iewportUpdate);
ui->GraphicsView->setBackgroundBrush(QBrush(bgPix));
ui->GraphicsView->setCacheMode(QGraphicsView::CacheBackground);
ui->GraphicsView->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
ui->GraphicsView->show();


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

Thanks

kapseli
25th September 2010, 00:18
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 :)

szisziszilvi
1st March 2011, 15:25
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. :)