PDA

View Full Version : Delete QGraphicsItems from scene



Diph
17th April 2010, 09:20
Hi

I have items in many levels (different zValue). I'm trying to delete items which aren't visible (smaller items above covers bigger item below). IsObscured method is not working because it checks if any of the items above are obscuring and they aren't because they are smaller: http://qt.nokia.com/doc/qt-maemo-4.6/qgraphicsitem.html

So in short, I want to check if smaller items cover bigger item.

lni
17th April 2010, 10:05
Use boundingRect()

Diph
17th April 2010, 13:28
I tried to combine bounding rects from smaller items and compare it to bounding rect of bigger item. But if I combine 4 100x100 items with QRectF.united() the resulting rect is 100x100, not 200x200.

I got it working, changed rect1.united(rect2) to rect1 = rect1.united(rect2). :D

Diph
17th April 2010, 15:00
Do you have better solutions? I did it this way (it seems to work but the algorithm looks ugly :D):


Combine smaller rects
If 4 rects was combined and combined items rect contains bigger items rect
delete bigger item