Results 1 to 3 of 3

Thread: Interacting QGraphicsItems together

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default Interacting QGraphicsItems together

    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

    Qt Code:
    1. public void dragEnterEvent(QGraphicsSceneDragDropEvent event)
    2. {
    3. System.out.println("Dragged on the item");
    4. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by wysota; 16th April 2011 at 07:57.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interacting QGraphicsItems together

    Why are you using drag events and not mouse move events?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default Re: Interacting QGraphicsItems together

    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...

    Qt Code:
    1. public void mouseReleaseEvent(QGraphicsSceneMouseEvent event)
    2. {
    3. //Code here to see if the item currently being dragged is on top of another item
    4. super.mouseReleaseEvent(event);
    5. }
    To copy to clipboard, switch view to plain text mode 


    Added after 1 3 minutes:


    Found the solution. ColodingItems...

    Qt Code:
    1. Block newBlock;
    2. List l1 = collidingItems(selectedBlock);
    3. for (int i = 0; i < l1.size(); i++)
    4. {
    5. newBlock = (Block)l1.get(i);
    6. newBlock.testSetColor(Block.blockState.HOVER);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by sean.reynolds; 16th April 2011 at 09:35.

Similar Threads

  1. Replies: 2
    Last Post: 8th December 2010, 10:51
  2. Replies: 5
    Last Post: 8th January 2010, 17:03
  3. Interacting with an API
    By srohit24 in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2009, 14:17
  4. qt application interacting with GSMmodem in windows
    By jjbabu in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2007, 11:22
  5. events interacting with signals/slots
    By gunhelstr in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2006, 12:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.