Drag and drop tree widget item into graphicsview
-
Hello, This is my simple code to drag tree-widget item. I have graphics-view in same window.
I want to drop item into graphicsview.
Heres my code to drag tree widget item.void SimplePlayer::dragEnterEvent(QDragEnterEvent *event) //should be for graphicsview { qDebug()<<"dragEnterEvent"; if (event->mimeData()->hasFormat("application/x-dnditemdata")) { if (event->source() == this) { event->setDropAction(Qt::MoveAction); event->accept(); } else { event->acceptProposedAction(); } } else { event->ignore(); } }
I am new to drag and drop. Which events are compulsory to implement?
How do I convert tree-widget item data to turn widget after dropping into graphics-view? -
Hi,
I usually implement:void dragEnterEvent(QDragEnterEvent *event)
void dragMoveEvent(QDragMoveEvent *event)
void dropEvent(QDropEvent *event)In the latter you will create the GraphicsView widget item according to information that you provide at the drag source: e.g. you can serialize the essential parameters of tree-widget item into a bytearray and in the dragEvent de-serialize it and use it to create a corresponding GraphicsView widget item. Nothing of this happens automatically.
- Michael.