Results 1 to 3 of 3

Thread: <Solved> How to handel Drag Events of Child QGraphicItems

  1. #1
    Join Date
    Aug 2015
    Posts
    25
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default <Solved> How to handel Drag Events of Child QGraphicItems

    Hi,

    recently I started to write a Node Editor.
    Right now I just use custom QGraphicsItems inside a standard scene.
    The Body of the Nodes use ItemIsMoveable, the Pins are Child Items derived from QGraphicsItem.

    The Pins.h file:
    Qt Code:
    1. #ifndef NODEINPUTPLUG_H
    2. #define NODEINPUTPLUG_H
    3.  
    4. #include <QGraphicsItem>
    5. #include <QPainter>
    6. #include <QMouseEvent>
    7. #include <QDrag>
    8.  
    9. class nodeinputplug : public QGraphicsItem
    10. {
    11. public:
    12. nodeinputplug();
    13.  
    14. QRectF boundingRect() const;
    15.  
    16. void paint(QPainter *painter,const QStyleOptionGraphicsItem *option, QWidget *widget);
    17.  
    18. QDrag *drag;
    19.  
    20. protected:
    21. void mousePressEvent(QGraphicsSceneMouseEvent *event);
    22. void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    23. void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    24. void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    25. void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    26. void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
    27. void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
    28. void dropEvent(QGraphicsSceneDragDropEvent *event);
    29. };
    30.  
    31. #endif // NODEINPUTPLUG_H
    To copy to clipboard, switch view to plain text mode 

    To check if the MouseEvents work i just put a qDebug() << event; in every of the Mouse handling functions.
    Everything works well except dragLeaveEvent.
    I tried to invoke draging like in the Drag and Drop Robot example. However if I try to create a drag object
    inside the mouseMoveEvent function I just get this Error Message:

    Qt Code:
    1. no matching function for call to 'QDrag::QDrag(nodeinputplug* const)'
    2. QDrag *drag = new QDrag(this);
    To copy to clipboard, switch view to plain text mode 

    I also tried to create a drag object inside the constructor, but this gives me roughly the same error.
    Do I have to derive from QObject also?
    Last edited by 0backbone0; 21st August 2015 at 01:22.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to handel Drag Events of Child QGraphicItems

    You could just pass the scene as the drag's parent.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    25
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to handel Drag Events of Child QGraphicItems

    Thank you for your answer.

    Unfortunately passing the Scene didn't work. I found another Solution thou.
    After I included QWidget I could pass the Widget of the event as argument.
    This still didn't invoke a drag action because the drag->exec() was missing.

    Qt Code:
    1. QDrag *drag = new QDrag(event->widget());
    2. QMimeData *mimeData = new QMimeData;
    3. drag->setMimeData(mimeData);
    4.  
    5. Qt::DropAction dropAction = drag->exec();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Getting keyboard events while in a drag and drop state
    By gerrysweeney in forum Qt Programming
    Replies: 5
    Last Post: 10th July 2012, 12:19
  2. QTreeView autoscrolling in drag move events
    By mentalmushroom in forum Qt Programming
    Replies: 2
    Last Post: 23rd September 2011, 14:56
  3. Handling parent und child events at once.
    By dentist in forum Newbie
    Replies: 3
    Last Post: 2nd April 2010, 11:55
  4. How to handel .xl files using Qt
    By dummystories in forum Qt Programming
    Replies: 0
    Last Post: 18th March 2009, 05:24
  5. Replies: 9
    Last Post: 22nd June 2008, 23:26

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.