You are creating a new QGraphicsScene
and QGraphicsView
every time you set a picture. And you are not putting your view
inside any layout or setting a parent to it, so it's opening in a new window when you call view->show()
.
You should create a QGraphicsView
and a QGraphicsScene
inside your constructor.
//picturearea.h
...
public:
QGraphicsView *view;
QGraphicsScene *scene;
...
//pircurearea.cpp
picturearea::picturearea(QWidget *parent) : QWidget(parent)
{
this->setLayout(new QVBoxLayout);
view = new QGraphicsView(this);
this->layout()->addWidget(view);
scene = new QGraphicsScene;
view->setScene(scene);
}
void picturearea::setPicture(QImage image)
{
scene->clear();
scene->addPixmap(QPixmap::fromImage(image));
}