[Qt-interest] remove QgRaphicsItem from parent

Riccardo Roasio riccardo.roasio at gmail.com
Mon Oct 12 15:00:44 CEST 2009


Seems to work...i will make more tests but for now thanks everybody!


Riccardo

2009/10/12 Rainer Wiesenfarth <Rainer.Wiesenfarth at inpho.de>:
>
> From: Josiah Bryan [mailto:jbryan at productiveconcepts.com]
>> I probably would do:
>>
>>   while (! elements.isEmpty ())
>>   {
>>       pointer = elements.takeFirst ();
>>         pointer->setParent(0);
>>         myGraphicsScene->removeItem(pointer);
>>         delete pointer;
>>   }
>>
>> Docs say setParent(0) sets removes the item from it's current
>> parent and
>> makes it a child of the QGraphicsScene (e.g. no parent.) Then we can
>> call removeItem() on the graphics scene to get it removed.
>> Finally, we
>> can delete the pointer once we're done with it.
>
> Docs say also:
>
>  QGraphicsItem::~QGraphicsItem () [virtual]
>
>  Destroys the QGraphicsItem and all its children. If this item is
>  currently associated with a scene, the item will be removed from
>  the scene before it is deleted.
>
> So removeItem() is not needed, as is probably the setParent(). Thus my
> initial suggestion:
>
>  while (! elements.isEmpty ())
>  {
>      delete elements.takeFirst ();
>  }
>
> This is as minimal as I would expect it to be. At least, since the
> setAutoDelete() was dropped ... ;-)
>
> Best Regards / Mit freundlichen Grüßen
> Rainer Wiesenfarth
>
> --
> INPHO GmbH * Smaragdweg 1 * 70174 Stuttgart * Germany
> phone: +49 711 2288 10 * fax: +49 711 2288 111 * web: www.inpho.de
> place of business: Stuttgart * managing director: Johannes Saile
> commercial register: Stuttgart, HRB 9586
> Leader in Photogrammetry and Digital Surface Modelling
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>




More information about the Qt-interest-old mailing list