Qt-interest Archive, August 2007
How to determine QGraphicsItem leaves viewport
Message 1 in thread
Hello,
I have got a list QGraphicsPixmapItem's which fetch some image data when
they become visible. This is easy to handle by checking the first call to
::paint method. I need the counterpart now. If the item is not being drawn
anymore, there is no need to keep the images in the memory and they can be
deleted.
So is there virtual method or some other way to determine if a QGraphicsItem
is now being painted anymore ?
Thanks in advance,
Devrim
Message 2 in thread
On 8/11/07, Devrim Erdem <devrim.erdem@xxxxxxxxx> wrote:
> Hello,
>
> I have got a list QGraphicsPixmapItem's which fetch some image data when
> they become visible. This is easy to handle by checking the first call to
> ::paint method. I need the counterpart now. If the item is not being drawn
> anymore, there is no need to keep the images in the memory and they can be
> deleted.
Well if you tell the QGraphcsItem that it clips to shape (one of the
graphics item flags) then paint will only be called for its
boundingRect, at which point you don't really need to check for
whether its being displayed. Secondly, instead of loading the pixmap
each time, you're probably better off placing the pixmap in the
QPixmapCache, and if its not being drawn, just let it fall out of
scope in the cache.
> So is there virtual method or some other way to determine if a QGraphicsItem
> is now being painted anymore ?
If you really need to check if its out of the viewport you can check
the current pos and compare that to the rect of the parenting
QGraphicsView, but this really shouldn't be necessary.
Cheers,
Matt Broadstone
> Thanks in advance,
>
> Devrim
>
--
[ signature omitted ]