Results 1 to 11 of 11

Thread: QGraphicsScene drag event

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    9
    Thanked 3 Times in 3 Posts

    Default Re: QGraphicsScene drag event

    I figured it out!!

    To support drag events for QGraphicsScene you must allow drops on the scene
    Qt Code:
    1. setAcceptDrops(true);
    To copy to clipboard, switch view to plain text mode 

    create a QDrag object with mime data in the mousePressEvent()
    Qt Code:
    1. QDrag *drag = new QDrag(this);
    2. drag->setMimeData(new QMimeData()); // does not work without mime data
    3. drag->exec();
    To copy to clipboard, switch view to plain text mode 

    and accept the drag event in dragEnterEvent()
    Qt Code:
    1. void dragEnterEvent(QDragEnterEvent *event) {
    2. event->acceptProposedAction();
    3. }
    To copy to clipboard, switch view to plain text mode 

    Then you can catch the dragMoveEvent()

    Phew - that's a lot of work. I would certainly prefer if mouseMoveEvent() still worked when the mouse button was down.
    Last edited by rbp; 11th February 2009 at 23:37. Reason: simplified code example

Similar Threads

  1. Custom event gets not propagated to the top level widget
    By nightghost in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2009, 09:06
  2. Drag & Drop when parent and childs accept drops?
    By gri in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2008, 09:00
  3. QGraphicsScene doesn't enter drag event
    By Radagast in forum Qt Programming
    Replies: 8
    Last Post: 16th June 2008, 17:21
  4. Qt event queue overloading?
    By gct in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2008, 18:39
  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
  •  
Qt is a trademark of The Qt Company.