Put an item on the QGraphicsView
-
Hi,
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));
this->addItem(item);
@but this doens't work :s
Kind regards,
-
Hi,
You need to add a scene to your graphics view and then add the QGraphicsPixmapItem to the scene
e.g@scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);QImage worldImage("your image path");
item = scene->addPixmap(QPixmap::fromImage(worldImage));@Where item is QGraphicsPixmapItem and scene is QGraphicsScene.
Try If this works.