Results 1 to 3 of 3

Thread: Handle Drag & Drop Events with QGraphicsItem [SOLVED]

  1. #1
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Handle Drag & Drop Events with QGraphicsItem [SOLVED]

    Ok, Problem found : I had to start the event with a QDrag of course
    Now, it works fine!

    Hello,

    I have a little problem with subclassing QGraphicsItem : everything works fine, bounding box, painting, etc, excepted that I cannot catch drag & drop events...

    My Item is part of a QGraphicsScene, rendered with a QGraphicsView, nothing special really...
    I have reimplemented the 3 protected functions for drag (dragEnter, dragMove, dropEvent..), but nothing happens.

    It seems that events aren't dispatched by the scene...I followed the Qt Drag And Drop Robot Example, and it works perfectly there...Any idea ?

    Thanks,

    Guilugi.
    Last edited by guilugi; 7th February 2007 at 16:16.

  2. #2
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Handle Drag & Drop Events with QGraphicsItem [SOLVED]

    Hi,

    I'm having the same problem but I don't understand what he wanted to say with "I had to start the event with a QDrag of course".

    I have a QGraphicsScene, QGraphics view and my items are moved perfectly by drag&drop... but the events are not catched.

    All the subclassed events called its parent event at the end, so I'm a bit lost.

    thanks!

    Edit: I forgot to say I already added setAcceptDrops(true)
    Last edited by jano_alex_es; 11th December 2009 at 12:52. Reason: updated contents

  3. #3
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: Handle Drag & Drop Events with QGraphicsItem [SOLVED]

    I know this thread is old but I found it through Google and just wanted to help people that stumble upon this thread.

    So if you want to Drag a QGraphicsItem you need to signal Qt when you want a Drag-Event to be started.
    So what guilugi forgot was to Generate a QDrag Object to let Qt know that a Drag event started.

    This is the example from the dragdroprobot-example:

    Qt Code:
    1. void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    2. {
    3. if (QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton))
    4. .length() < QApplication::startDragDistance()) {
    5. return;
    6. }
    7.  
    8. QDrag *drag = new QDrag(event->widget());
    9. QMimeData *mime = new QMimeData;
    10. drag->setMimeData(mime);
    11. /* . . . */
    12. drag->exec();
    13. /* . . . */
    14. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Drag & drop with model/view (Qt4)
    By yogeshm02 in forum Qt Programming
    Replies: 16
    Last Post: 19th September 2011, 20:36
  2. Drag and Drop
    By allensr in forum Qt Programming
    Replies: 1
    Last Post: 11th December 2006, 20:50
  3. Windows OLE drag & drop
    By Lele in forum Qt Programming
    Replies: 1
    Last Post: 12th September 2006, 09:47
  4. Replies: 7
    Last Post: 8th September 2006, 16:19
  5. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41

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.