Search code examples
qtqgraphicsitemqgraphicsscene

Get item's parent scene after QGraphicsScene::addItem ( QGraphicsItem * item )


I create a new QGraphicsItem named myItem. And in the mainwindow.cpp file I have a QGraphicsScene scene. In the constructor of mainwindow:

ui->setupUi(this);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
item = new myItem();
scene->addItem(item);

This works fine. I can see my item on the scene. But now I want to get the scene in myItem.cpp file. How can I do this?
Thank you in advance!


Solution

  • auto myScene = scene();
    

    Please read the docs first.