not quite sure I'm understanding the question correctly, but your mime data comes from the startDrag method, where you've created a QMimeData object, set it's type and supplied data accordingly. In your dropEvent method check the type of the incoming data and process it accordingly or ignore if you don't recognize the type.
Also take a look at the documentation here: Drag and Drop it should give you an idea on how drag and drop works in qt
I also made a small example here, see if it would work for you:
import sys
from PyQt4 import QtGui, QtCore
class TestTreeWidget(QtGui.QTreeWidget):
def __init__(self, parent = None):
super(TestTreeWidget, self).__init__(parent)
self.setDragEnabled(True)
self.setAcceptDrops(True)
def startDrag(self, dropAction):
# create mime data object
mime = QtCore.QMimeData()
mime.setData('application/x-item', '???')
# start drag
drag = QtGui.QDrag(self)
drag.setMimeData(mime)
drag.start(QtCore.Qt.CopyAction | QtCore.Qt.CopyAction)
def dragMoveEvent(self, event):
if event.mimeData().hasFormat("application/x-item"):
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
else:
event.ignore()
def dragEnterEvent(self, event):
if (event.mimeData().hasFormat('application/x-item')):
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if (event.mimeData().hasFormat('application/x-item')):
event.acceptProposedAction()
data = QtCore.QString(event.mimeData().data("application/x-item"))
item = QtGui.QTreeWidgetItem(self)
item.setText(0, data)
self.addTopLevelItem(item)
else:
event.ignore()
class MainForm(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
self.view = TestTreeWidget(self)
self.view.setColumnCount(1)
item0 = QtGui.QTreeWidgetItem(self.view)
item0.setText(0, 'item0')
item1 = QtGui.QTreeWidgetItem(self.view)
item1.setText(0, 'item1')
self.view.addTopLevelItems([item0, item1])
self.setCentralWidget(self.view)
def main():
app = QtGui.QApplication(sys.argv)
form = MainForm()
form.show()
app.exec_()
if __name__ == '__main__':
main()
also you may want to take a look at the similar post here: QTreeView with drag and drop support in PyQt
hope this helps, regards