PDA

View Full Version : How to delete a QGraphicsPixmapItem in a scene.



newqtuser
7th July 2009, 16:31
I was wondering if anyone knows a quick way i can tell when a QGraphicsPixmapItem is not visable by the view? I have a normal scene and view, i place items on there 1 by 1 and move the view by using setSceneRect. I need to be able to delete the items that are no longer visable on the scene. My items are subclassed from QGraphicsPixmapItem and Ive tried ItemVisibleHasChanged and that doesnt seem to be working. Im only moving the view and not the items. Thanks

wysota
7th July 2009, 16:43
Try this:

bool visibleOnView = view->sceneRect().intersects(item->boundingRect());

or alternatively:

bool visibleOnView = view->mapToScene(viewport()->rect()).intersects(item->boundingRect());

newqtuser
9th July 2009, 02:36
Thanks for the help on that, is there anyway of specifying only the right side of the view->sceneRect(), so if an item is moving to the right side then visibleOnView would be true?

wysota
9th July 2009, 08:07
Substitute viewport()->rect() with whatever you want.