PDA

View Full Version : how to hide QgraphicsItem !!!



peace_comp
23rd May 2008, 16:02
Hi..
I have a problem of how to use correcty the QGraphicsItemGroup ..
well. my application is about zooming on a map .. so depending on the zoom I should display or hide some details..
for example to put the names of cities after zooming I used:


void myview::zoomingin(){

for (int i=0;i<5;i++){
QGraphicsTextItem * txt=new QGraphicsTextItem(citiesName[i]);
txt->setPos(citiesX[i],citiesY[i]);
scene->addItem(txt);
group->addToGroup(txt);
}
graphicsView->scale(1.2,1.2);
}
>> citiesName,citiesX,citiesY are QList containin' the names and coordonates of each citie..

then I should hide them when we zoom out .. I try to used:

void myview::zoomingout(){

scene->destroyItemGroup(group);

graphicsView->scale(1/1.2,1/1.2);
}

but it doesnt work .. nd when the group became empty it stucks!!

plz if someOne have a idea !!!!!!!!!!!!!!!!!!!!!!:confused:

init2null
23rd May 2008, 18:20
Hello peace_comp, here's a quote from the docs about destroyItemGroup:


void QGraphicsScene::destroyItemGroup ( QGraphicsItemGroup * group )
Reparents all items in group to group's parent item, then removes group from the scene, and finally deletes it. The items' positions and transformations are mapped from the group to the group's parent.

So it sounds like you'll need to delete each label individually. If you want to keep using an ItemGroup, just loop through its childItems() and delete them individually before removing the group.

Hope this helps,

Wesley

aamer4yu
24th May 2008, 09:46
well, see the 40000 chip demo,,, they hide details depending on zoom level, It might help u.

Also based on zoom level, u can emit a signal from the scene to some handler class. In the handler class, hide the graphic items u want to hide :)