Logo Search packages:      
Sourcecode: qt4-x11 version File versions

bool QGraphicsItem::collidesWithItem ( const QGraphicsItem other,
Qt::ItemSelectionMode  mode = Qt::IntersectsItemShape 
) const [virtual, inherited]

Returns true if this item collides with other; otherwise returns false. The ways items collide is determined by mode. The default value for mode is Qt::IntersectsItemShape; other collides with this item if it either intersects, contains, or is contained by this item's shape.

The default implementation is based on shape intersection, and it calls shape() on both items. Because the complexity of arbitrary shape-shape intersection grows with an order of magnitude when the shapes are complex, this operation can be noticably time consuming. You have the option of reimplementing this function in a subclass of QGraphicsItem to provide a custom algorithm. This allows you to make use of natural constraints in the shapes of your own items, in order to improve the performance of the collision detection. For instance, two untransformed perfectly circular items' collision can be determined very efficiently by comparing their positions and radii.

Keep in mind that when reimplementing this function and calling shape() or boundingRect() on other, the returned coordinates must be mapped to this item's coordinate system before any intersection can take place.

See also:
contains(), shape()

Definition at line 2734 of file qgraphicsitem.cpp.

References QGraphicsItem::collidesWithPath(), QGraphicsItem::mapFromItem(), and QGraphicsItem::shape().

Referenced by QGraphicsScene::collidingItems(), and Arrow::paint().

    if (other == this)
        return true;
    if (!other)
        return false;
    return collidesWithPath(mapFromItem(other, other->shape()), mode);

Generated by  Doxygen 1.6.0   Back to index