Hi all,
Suppose to have 2 items derived from qgraphicsitem, container and object, and suppose to override the object mouseReleaseEvent.
I do this:
IamInaContainer=false;
if(!scene()->collidingItems(this).isEmpty()){
QList<QGraphicsItem*> lista_Ogge=scene()->collidingItems(this);
for(int u=0;u<lista_Ogge.size();u++){
if((lista_Ogge.at(u))->type()==soa_container::Type){
IamInaContainer=true;
setParentItem(lista_Ogge.at(u));
break;
}
}
}
if(!IamInaContainer)setParentItem(0);
IamInaContainer=false;
if(!scene()->collidingItems(this).isEmpty()){
QList<QGraphicsItem*> lista_Ogge=scene()->collidingItems(this);
for(int u=0;u<lista_Ogge.size();u++){
if((lista_Ogge.at(u))->type()==soa_container::Type){
IamInaContainer=true;
setParentItem(lista_Ogge.at(u));
break;
}
}
}
if(!IamInaContainer)setParentItem(0);
To copy to clipboard, switch view to plain text mode
everythings is good , i'm able to move the object inside a container and then if i move container the object is moved right.Also i can move the object away from the container and setparent(0) work fine.
The problem is the draw position. When i insert the object inside the container the object don't stay where i released the mouse button, but shift (apparently) by a random vector.
Also when i drag the object away from container (suppose to move the object 50 pixel away the container) the object, after release, is drawn somewhere in the scene.
Notice that if i comment out this line:
//setParentItem(lista_Ogge.at(u));
//setParentItem(lista_Ogge.at(u));
To copy to clipboard, switch view to plain text mode
Everythings is good about positioning, never got a random offset from release to draw point, but offcourse object is ever without parent.
I think i missing sometimes about child/parent position.
Thx in advice.
Bookmarks