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?
Code:
QPixmap bgPix
(":/Time-For-Lunch-2.jpg");
ui
->GraphicsView
->setViewportUpdateMode
(QGraphicsView::BoundingRectViewportUpdate);
ui
->GraphicsView
->setBackgroundBrush
(QBrush(bgPix
));
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
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 :)
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. :)