PDA

View Full Version : drag&drop from QTreeWidget to QGraphicsPixmapItem



hakiim35
31st August 2010, 13:45
Hi, I want to drag a QTreeWidgetItem from my QTreeWidget to the QGraphicsPixmapItem.
Do I have to reimplement mouse events in the drag site.
I reimplemented them such as
mousePressEvent(QGraphicsSceneMouseEvent *e);
mouseMoveEvent(QGraphicsSceneMouseEvent *e);
mouseReleaseEvent etc..
but the program flow never falls into the mouse events in debug mode.
I have also performed setAcceptDrops(true) in my QGraphicsPixmapItem's constructor and reimplemented the dropEvent( QDropEvent *event ) but again the flow never falls inside it.

How will I be able to perform the drag & drop?
My aim is to send the currently dragged QTreeWidgetItem's text to the QGraphicsPixmapItem.

Best regards.

moez
5th September 2010, 23:15
Before starting to debug make you sure you have these things set properly:

- A correct Start of a drag operation (enable dnd and reimplement the necessary event handler i can send you to this link http://doc.qt.nokia.com/4.6/dnd.html

ad this one

http://web.njit.edu/all_topics/Prog_Lang_Docs/html/qt/simple_dd-example.html



-The QGraphicsView container where you want to drop your item is interactive with : ( void QGraphicsView::setInteractive ( bool allowed ) ).

- The QGraphicsView container where you want to drop your item accept drop events with : QGraphicsView::setAcceptDrops(true);

- if you're subclassing QGraphicsPixmapItem set your class it to accept drop with : void QGraphicsItem::setAcceptDrops ( bool on )

then reimplement

dropEvent ( QGraphicsSceneDragDropEvent * event ) of your subclass and process the data contained in the event->mimeData().

This data (the text ) should be loaded in the start drag processing.