I am using a QTableView, on which I set my own custom model, inheriting from QAbstractTableModel, using a call to QTableView::setModel().
The table view supports drag and drop: my model class reimplements mimeData() and dropMimeData(). Items can be dragged and dropped, even between 2 instances of the application.
What I'd like to achieve is: dropMimeData() should detect whether the dropped element comes from the same window, or from another window of another running copy of the application. And it should behave differently in each case.
Using the argument Qt::DropAction action of dropMimeData() seemed the most natural thing, but that does not work: it is always Qt::CopyAction or Qt::MoveAction, irrespective of the originating window, and only depending on the defaultDropAction of the QTableView.
Is this possible?
I ended up subclassing
QTableView
, which can be done in QT Designer by right-clicking on the table in the form and choosing Promote to...- In the subclass I followed adlag's suggestion and useddropEvent->source()
to detect whether the source was the same widget or another one.