Thanks for the answer, I totally agree. I think I was a bit thrown by the fact that changing view modes in the QListWidget would change the selectedItems() order.
I fixed this entirely in 2 places. First I overloaded selectedItems:
def selectedItems(self):
indexes = self.selectionModel().selectedIndexes()
indexes.sort(cmp=lambda a, b : cmp(a.row(), b.row()))
items = [self.itemFromIndex(index) for index in indexes]
return items
def mimeData(self, items):
ordered_items = []
for idx in range(self.count()):
item = self.item(idx)
if item in items:
ordered_items.append(item)
...
def selectedItems(self):
indexes = self.selectionModel().selectedIndexes()
indexes.sort(cmp=lambda a, b : cmp(a.row(), b.row()))
items = [self.itemFromIndex(index) for index in indexes]
return items
def mimeData(self, items):
mimedata = QtCore.QMimeData()
ordered_items = []
for idx in range(self.count()):
item = self.item(idx)
if item in items:
ordered_items.append(item)
...
To copy to clipboard, switch view to plain text mode
the mimeData implementation is not exactly optimized, but for some reason QListWidgetItems dont seem to have an index() method to get their model index. Otherwise I would also sort them by their rows
Bookmarks