PDA

View Full Version : QGraphicsItemGroup adding/removing items



mongooseblarg
8th July 2010, 22:36
Howdy Qt goers,
I'm having a little trouble.
I've got a QGraphicsScene that contains a bunch of QGraphicsItemGroups.
You can zoom in and out, and I have content that shows up when you zoom in far enough.
When optimizing the drawing speed, I found that using addToGroup when zoomed in far enough and removeFromGroup when you zoom out far enough is the most efficient way of showing/hiding content (a LOT of content).

So, I've gotten it to addToGroup appropriately when zoomed in, but when I zoom out, it blinks as though it called removeFromGroup, but then it's still there. I have a feeling it's because of my implementation of levelOfDetailFromTransform().

This is my paint() function for each QGraphicsItemGroup



const qreal lod = item->levelOfDetailFromTransform(painter->worldTransform());
if(lod > .05)
{
if(childItems().size()==0)
for(int index=0;index<siteItems.size();index++)
addToGroup(siteItems[index]);
}
else
{
if(childItems().size()!=0)
for(int index=0; index < siteItems.size();index++)
removeFromGroup(siteItems[index]);
}


I know the level of detail is calibrated about right, but for some reason, this implementation just doesn't want to remove the items.
Again, for instance, I'll zoom in, and the items that are zoomed in show up like they should because of addToGroup(), but I'll zoom out and those items specifically will persist.

Thanks!