I have my own class inheriting from QListWidgetItem and another inheriting from QListWidget. I am trying to make Drag and Drop work properly. I want to insert items exactly where indicator is. I can't use standard QListWidget.dropEvent because then it's trying to drop QListWidgetItems... not objects of my class. Here is part of my dropEvent but It's not really good:
def dropEvent(self, event):
item=event.source().currentItem().clone()
oldrow=event.source().row(event.source().currentItem())
o=event.source().takeItem(oldrow)
del(o)
cursorpos=self.mapFromGlobal(QtGui.QCursor.pos())
itembefore=self.itemAt(cursorpos)
print itembefore
if itembefore:
row=self.row(itembefore)
self.insertItem(row, item)
else:
self.addItem(item)
Now it always drops items After the item you drop on... and it's not always where indicator is shown. Some ideas?