Drag and drop between QTableView and QGraphicsView (from model to model)
I have a QTableView (its model is QStandardItemModel) and I have a QGraphicsView (its model is a QGraphicsScene). I'd like to copy/move an item (an icon with text) from the table into the graphics area.
How can I solve this?
You will need to implement it yourself. There is no feature in Qt that does all this automatically, but it certainly can be done (from experience, I have done it).
Yes, I know that I have to implement it myself.
But I have no idea, how can I solve it.
My main problem is with the model...
QGraphicsView forwards drag & drop events to the scene. "This section":/doc/qt-4.8/graphicsview.html#drag-and-drop in the documentation should get you started.
What I have done till now:
I have a subclassed QTableView. I reimplemented the mouseMoveEvent function. Here I assembled the mimedata and started the drag.
This event is running good when I drag a row from the table.
This is a subclassed QGraphicsView, here I have some pixmap on the scene (and on the view). I reimplemented the dragEnterEvent what is running good.
I reimplemented the dropEvent too, but this event doesn't run at all...
void DisplayLayout::dropEvent(QDropEvent* event)
qDebug() << "dropEvent" ;
(And what is the different between event->acceptProposedAction(); and event->setAccepted(true); ?)
Another "helpful wiki entry":https://qt-project.org/doc/qt-4.8/model-view-programming.html#using-drag-and-drop-with-item-views on the subject.
Make sure you have enabled drag & drop in both views, and that the mime data is accepted.
Thx the link, I've read this article.
My mimedata seems to be good.
I've set in the views the setDragEnabled(true) and setAcceptDrops(true);
What I'd like to: select a row in the table (get the ID), and I pass this ID into the graphicsview, and added a pixmap with this ID.
But I have no succes :(