QPixmap in GraphicsView ??
I have been trying to get a image to show in a GrapichsView.
But after alot of trail and error I have not got it to work.
Would anyone be so kind to point me in the right direction?
Code:
ui->graphics_ImgLib->setScene(&scene);
image.load(":/IMG/IMG/logo.png");
scene.addPixmap(image);
pixMapItem.setPixmap(image);
scene.addItem(&pixMapItem);
ui->graphics_ImgLib->show();
Thanks for any help.
Cheers
WetCode
Re: QPixmap in GraphicsView ??
What is the scope of the QGraphicsScene instance? My guess is that "scene" is going out of scope immediately or the pixmap is not in the resource file location you think it is.
Re: QPixmap in GraphicsView ??
I am wery certen the image is there as i am displaying it several places.
When you say out of scope, do you mean its not within the QGrapichsView ?
Re: QPixmap in GraphicsView ??
No, I mean scope of time over which the QGraphicsScene object exists. If you create the scene on the stack (as in your example) the object ceases to exist when the variable goes out of scope (i.e. usually at the end of the enclosing { } block). When the scene is destroyed the view has nothing to display, and that's what you see. The QGraphicsScene must exist as long as the view needs to display it.
This is generic C++ and not specific to Qt.