PDA

View Full Version : Interacting QGraphicsItems together



sean.reynolds
16th April 2011, 08:27
Hey Guys,

I currently have a graphics scene with dynamic QGraphicsItems being added to the scene. I would like to snap these items together by dragging one item on top of another and releasing the mouse button.

In the QGraphicsItem class i have the following function



public void dragEnterEvent(QGraphicsSceneDragDropEvent event)
{
System.out.println("Dragged on the item");
}

This code works fine when I drag some item from my desktop (say an Excel file), but it doesn't detect any item in my scene beign dragged on top of it.

Any help would really be appreciated.

Thanks

wysota
16th April 2011, 08:58
Why are you using drag events and not mouse move events?

sean.reynolds
16th April 2011, 10:35
I thought I could use DragEvents....initially i tried dealing with mouseMove

If i used a mouse move event and detect the itemAt a particularpoint, it always returns the item i'm currently dragging (top most item).

If I wanted it to snap on top of another QGraphicsItem, can I use the mouseReleaseEvent in the QGraphicsScene

like...




public void mouseReleaseEvent(QGraphicsSceneMouseEvent event)
{
//Code here to see if the item currently being dragged is on top of another item
super.mouseReleaseEvent(event);
}



Added after 1 3 minutes:

Found the solution. ColodingItems...



Block newBlock;
List l1 = collidingItems(selectedBlock);
for (int i = 0; i < l1.size(); i++)
{
newBlock = (Block)l1.get(i);
newBlock.testSetColor(Block.blockState.HOVER);
}