Put an item on the QGraphicsView
I've created via the designer a form with a qgraphicsview in it. Now in my constructor of the mainwindow I would like to place a image in the view, but nothing works. I thought I could do it with ui->nameofview->addPixmapItem but I can't?
It's the first time it do this via the designer so what is wrong with?
In my previous project I did it without the creator with this code:
item = new QGraphicsPixmapItem( QPixmap::fromImage(worldImage));
but this doens't work :s
Is the image linked well? I've seen a lot of threads where the filepaths aren't formed well.
You need to add a scene to your graphics view and then add the QGraphicsPixmapItem to the scene
@scene = new QGraphicsScene(this);
QImage worldImage("your image path");
item = scene->addPixmap(QPixmap::fromImage(worldImage));@
Where item is QGraphicsPixmapItem and scene is QGraphicsScene.
Try If this works.
Jup forgot this because of the creator :-) thanks.
Yes this is very common mistake, even i got confused initially when using the graphicsView. Kindly Edit your first Post and mark it [SOLVED],
Happy Coding !!!!