Colliding: mapToScene seems not to work
-
I'am trying to handle collision between an item that is child of another one (its main item), with an individual item.
Both have set:
@
this->setFlags(QGraphicsItem::ItemClipsToShape);
@If collision is done, then I want to check if one point of the children shape is inside the other' shape:
@
QPointF pointC = cable->getCableArrowPoint();
QPainterPath path = this->shape();
path = this->mapToScene(path);
pointC = cable->mapToScene(pointC);
qDebug() << "Path: " << path << " and point: " << pointC;
if (path.contains(pointC)){
connected.append(cable);
cable->connectedWith = this;
cable->ONLINE = true;
}else{
disconnectCable(cable);
cable->ONLINE = false;
cable->connectedWith = 0;
}
@But its really strange: in scene, I can see how the pointC is inside (graphically), but @if (path.contains(pointC))@ is false.
Collision is called, but the point is not inside the shape!! Even if I can see graphically it is!!!! qDebug writes following lines:
@
Path: QPainterPath: Element count=5
-> MoveTo(x=251, y=312.75)
-> LineTo(x=263, y=312.75)
-> LineTo(x=263, y=372.25)
-> LineTo(x=251, y=372.25)
-> LineTo(x=251, y=312.75)
and point: QPointF(266, 330)
@Please, can you help me? Why "x" seems being misplaced? maybe "contains." or mapToScene? I've used these functions with other items (w/o ancestors) and they work fine!
Thank you.