Hi
I hava a problem with collision detection. in the picture below the lable Cargo5.5 dosn't detect collision with the QGraphicsPathItem belonging to Cargo6. The outline of the lables is the shape() of the item.
http://www.tiny.cc/ShWEW
the implementation of shape() looks like this
{
path.addRect(this->boundingRect().adjusted(0,4,0,-4));
return path;
}
QPainterPath SVGText::shape() const
{
QPainterPath path;
path.addRect(this->boundingRect().adjusted(0,4,0,-4));
return path;
}
To copy to clipboard, switch view to plain text mode
and the function where i test for collision, this is where the m_pTextItem e.g Cargo5.5 dosn't detect collision with the QGraphicsPathItem
altough the shape of Cargo5.5 intersects/contains with the QGraphicsPathItem of Cargo6
int SVGPath::TextCollitionCount()
{
int collCount = 0;
QList<QGraphicsItem *> collidingWithList = m_pTextItem->collidingItems(Qt::ContainsItemShape);
collCount = collidingWithList.count();
if(collCount)
{
for(QList<QGraphicsItem*>::iterator it = collidingWithList.begin();it != collidingWithList.end();)
{
if((*it)->type() == SVGPath::Type)
{
SVGPath *item = qgraphicsitem_cast<SVGPath *>(*it);
if(m_pTextItem->collidesWithPath(item->shape(),Qt::ContainsItemShape))
it++;
else
it = collidingWithList.erase(it);
}
}
}
}
int SVGPath::TextCollitionCount()
{
int collCount = 0;
QList<QGraphicsItem *> collidingWithList = m_pTextItem->collidingItems(Qt::ContainsItemShape);
collCount = collidingWithList.count();
if(collCount)
{
for(QList<QGraphicsItem*>::iterator it = collidingWithList.begin();it != collidingWithList.end();)
{
if((*it)->type() == SVGPath::Type)
{
SVGPath *item = qgraphicsitem_cast<SVGPath *>(*it);
if(m_pTextItem->collidesWithPath(item->shape(),Qt::ContainsItemShape))
it++;
else
it = collidingWithList.erase(it);
}
}
}
}
To copy to clipboard, switch view to plain text mode
is there something i have missed? stacking of items shouldn't matter should it? this application has no paint event etc it's sort of a static presentation (for now) so everyting is added to the scene and later on i set scene to the view.
Regards Muffin www.a-eon.com
Bookmarks