Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
4.8.7, 5.6.3, 5.9.9, 5.12.8, 5.14.2
-
None
Description
#include <QApplication> #include <QTreeWidget> int main(int argc, char **argv) { QApplication app(argc, argv); QTreeWidget widget; widget.setSelectionMode(QAbstractItemView::ExtendedSelection); widget.setDragDropMode(QAbstractItemView::InternalMove); for (int index = 0; index < 10; ++index) { auto item = new QTreeWidgetItem(&widget); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled); item->setText(0, QString::number(index)); } widget.show(); return QApplication::exec(); }
Select items 1, 3, 5, 7, 9 (in this order), drag and drop them below item 6.
Expected result is 0, 2, 4, 6, 1, 3, 5, 7, 9, 8,
but the actual one is 0, 2, 4, 6, 8, 1, 3, 9, 7, 5.
What's going on: the persistent index — that should guide the insertions — is one of the selected and becomes invalid after the removals. Now QTreeWidget tries to insert at the position determined by the dropOn call (row 7); when it is not possible, it inserts at the end (items 1, 3), and when it becomes possible, the insertions produce a reversed sequence (items 5, 7, 9).