Remove QGraphicsItem* from QGraphicsScene, and readd



  • I has a QMap<ItemID,QGraphicsItem*> mMap, The number of QGraphicsItem * is more than 1.

    1. I add one QGraphicsItem * named as Item1 into QGraphicsScese using scene->addItem. Item shows correct.
      2.call scene->clear() , and add another QGraphicsItem * named as Item2,Item2 shows correct.
      3.but now , if i readd Item1 into scene, item1 can't show correct. and i found the address of Item1 in mMap had been changed to 0xfeeefeee.

    does the scene->clear() delete the Item1 ?
    how can i do if i want to show these QGraphicsItems more than one time ?



  • From the first line of the QGraphicsScene::addItem() docs:
    @
    Adds or moves the item and all its childen to this scene. This scene takes ownership of the item.
    @
    So yes, the scene will delete any item still in it. You want QGraphicsScene::removeItem()



  • Thanks for your reply.

    i read the removeItem‘s docs, it should fit my requirement.

    [quote author="ChrisW67" date="1364361826"]From the first line of the QGraphicsScene::addItem() docs:
    @
    Adds or moves the item and all its childen to this scene. This scene takes ownership of the item.
    @
    So yes, the scene will delete any item still in it. You want QGraphicsScene::removeItem()[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.