So, my current list code allows me to drag and drop files onto a computer into my list. I want to be able to reorder the list items, the problem is when I try to overwrite it using the drop method to import files, and nothing happens. For example, if you drag from the outside of the listview, I want it to be imported if the drag is internal or, rather, from the inside of the list, I would like it to just move in the same way as using InternalMove.
Adding this code to my code:
self.listView.setDragDropMode(QtGui.QAbstractItemView.InternalMove);
Commenting this out:
def dropEvent(self, event): if event.mimeData().hasUrls: event.setDropAction(QtCore.Qt.CopyAction) event.accept() links = [] for url in event.mimeData().urls(): links.append(str(url.toLocalFile())) self.emit(QtCore.SIGNAL("dropped"), links) else: event.ignore()
It makes reordering work flawlessly, but does not allow me to import files by dragging and dropping them.
Because of this, I realized that this is the cause of my problems, but I just canβt figure out how to fix it and work at the same time, it seems that this should be an easy solution.
I do not know if this is correct, but I know:
if event.mimeData().hasUrls:
Returns true if outside the listview, and returns false if inside the listview
You will probably notice that the code above is: http://tech.xster.net/tips/pyqt-drag-images-into-list-widget-for-thumbnail-list/ as well as http://zetcode.com/tutorials / pyqt4 / dragdrop /
I know that I can create a setting that the pos mouse asks for and removes the item and re-adds it to the nearest position, but this seems like so many problems when InternalMove is built in and works for my needs.
Any help would be greatly appreciated, thanks for the time!