How to determine that two graphic objects stand side by side on a graphic scene? For example, I want to move objects around the scene with the mouse, but to put them not in an arbitrary position, but in a certain cell in the GridLayout, how to determine that they became nearby in the neighboring cells?

    1 answer 1

    QGraphicsGridLayout (unless of course we are talking about it) has a method:

     QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int row, int column) const 

    ... returning a pointer to the location manager's cell object. And from it you can get the element itself:

     QGraphicsItem *QGraphicsLayoutItem::graphicsItem() 

    Neighboring elements relative to the desired can be obtained in the same way. Then you simply compare the pointers or, using other criteria, determine that the elements in the neighboring positions correspond to the desired ones.