QListWidget Drag & Drop External File Drop and Internal Reordering
Hi,
I am trying to have a QListWidget that accepts both external file drop and InternalMove for reordering.
I came up with 2 solutions:
- one that shows the drop indicator in both cases but in the reordering allows to drop outside
- one that has the internalmove working correctly but on external drop there is no dropindicator.
First Solution
- def __init__(self, parent=None):
- super(FileList, self).__init__(parent)
- self.setDragEnabled(True)
- self.setAcceptDrops(True)
- self.setDropIndicatorShown(True)
- #to allow internal reordering
- def dropMimeData(self, index, mimeData, action):
- if mimeData.hasUrls():
- for url in mimeData.urls():
- self.insertItem(index, item)
- return True
- def mimeTypes(self):
- return ["text/uri-list"]
Second Solution
- def __init__(self, parent=None):
- super(FileList, self).__init__(parent)
- self.setAcceptDrops(True)
- self.setDragEnabled(True)
- self.setDropIndicatorShown(True)
- def dragEnterEvent(self, event):
- if event.mimeData().hasUrls():
- event.acceptProposedAction()
- else:
- super(FileList,self).dragEnterEvent(event)
- def dragMoveEvent(self, event):
- if event.mimeData().hasUrls():
- event.acceptProposedAction()
- else:
- super(FileList, self).dragMoveEvent(event)
- def dropEvent(self, event):
- if event.mimeData().hasUrls():
- urls = event.mimeData().urls()
- if urls:
- for url in urls:
- event.acceptProposedAction()
- super(FileList, self).dropEvent(event)
How can I combine this two to have drop indicator on external drop (like in the first example with dropMimeData) and allow internalMove (like in the second example)?
0 replies
You must log in to post a reply. Not a member yet? Register here!
