Returns a list of all items that collide with item. Collisions are determined by calling QGraphicsItem::collidesWithItem(); the collision detection is determined by mode. By default, all items whose shape intersects item or is contained inside item's shape are returned.
The items are returned in descending stacking order (i.e., the first item in the list is the uppermost item, and the last item is the lowermost item).
可以查看一下collidingItems的源码
QList<QGraphicsItem *> QGraphicsScene::collidingItems(const QGraphicsItem *item, Qt::ItemSelectionMode mode) const
{
Q_D(const QGraphicsScene);//宏通过d_func()获取d指针
if (!item) {
qWarning("QGraphicsScene::collidingItems: cannot find collisions for null item");
return QList<QGraphicsItem *>();
}
// Does not support ItemIgnoresTransformations.
QList<collidingItems *> tmp;
//获取Scene全部范围的Item
const auto itemsInVicinity = d->index->estimateItems(item->sceneBoundingRect(), Qt::DescendingOrder);
for (QGraphicsItem *itemInVicinity : itemsInVicinity) {
//使用QGraphicsItem的碰撞检测函数测试返回值
if (item != itemInVicinity && item->collidesWithItem(itemInVicinity, mode))
tmp << itemInVicinity;
}
return tmp;
}