Nominate our 2022 Qt Champions!

what should i do when i close a QGraphicsView/Scene with many QGraphicsItems added into the scene

  • i want to close and open QGraphicsView/Scene dynamically?
    what should i do when i click the close button? should i removeItem, then delete pItem, pItem = NULL in the QGraphicsView/Scene's destructor? or should i do this in QGraphicsView/Scene's closeEvent?
    ps. will QGraphicsItem automatically delete when removeItem from the scene, while when create the QGraphicsItem, no parent was sent to its constructor.
    thank you!

  • " when i close a QGraphicsView/Scene..."

    If you mean when you delete scene, all items in the scene will be deleted.
    From the top of the head removeItem does not delete it.
    And you do not need to remove item if you want to delete it.
    Just delete it ( delete item; ) .

    I am pretty sure documentation have more detailed explanation.

  • what will happen if i delete an item while it has been added to the scene?
    should i removeItem first, and then delete it?

Log in to reply