Unsolved Drag and Drop internal move bug creating additional rows with sort enabled.
-
I've seem to run into a drag and drop bug using an internal move event that causing the model to add additional rows and offset column data.
centos7, Qt 5.12in the example below I can replicate this every time by the following steps explicitly(DO NOT sort the Name column) :
parent-3 should be the top node.- select child item "4" from parent-3
- select child item "2" from parent-1
- drag and drop the two items over the parent-0
this moves the two rows("4" & "2") and creates two more with no DisplayRole in the name column. The "Tag" & "Color" data from the two item rows are shifted to the additional rows.
You can close and relaunched the application, now if you sort the Name column where parent-0 is the top node and try the step again, no additional rows are created.
Can any one reproduced this? Is there something with the sort I'm missing or is this a bug?
Cheersimport sys from PySide2 import QtWidgets, QtGui from PySide2.QtCore import Qt class SnippetTreeView(QtWidgets.QTreeView): def __init__(self, parent=None): super(SnippetTreeView, self).__init__(parent) self.setContextMenuPolicy(Qt.CustomContextMenu) self.setDragEnabled(False) self.setDragDropOverwriteMode(False) self.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove) self.setAlternatingRowColors(True) self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) self.header().setStretchLastSection(True) self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) def create_tag_color_items(): item_tag = QtGui.QStandardItem('tag') item_tag.setDropEnabled(False) item_color = QtGui.QStandardItem('color') item_color.setDropEnabled(False) return item_tag, item_color def add_items(model): headers = [ 'Name', 'Tag', 'Color', ] model.setHorizontalHeaderLabels(headers) model.setColumnCount(len(headers)) for num in range(4): parent_item = QtGui.QStandardItem('parent-' + str(num)) parent_item.setDropEnabled(True) item_tag, item_color = create_tag_color_items() for n in range(num + 2): child_item = QtGui.QStandardItem(str(n) ) child_item.setDropEnabled(False) ch_item_tag, ch_item_color = create_tag_color_items() parent_item.appendRow([child_item, ch_item_tag, ch_item_color]) model.appendRow([parent_item, item_tag, item_color]) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) tree = SnippetTreeView() tree.setSortingEnabled(True) model = QtGui.QStandardItemModel() add_items(model) tree.setModel(model) tree.expandAll() tree.show() rec = app.exec_() sys.exit(rec)
-
Hi,
Looks like a bug, it happens also with PySide2 5.15.0
Can you reproduce that with the C++ equivalent of your code ?
-
Hi @SGaist ,
Don't have 5.15 installed but I did submit a report though pyside and it was bumped to the main qt :
https://bugreports.qt.io/browse/QTBUG-85324 -
Thank you !