QListView 实现拖放内部移动删除项目而不是移动它们

tes*_*t11 5 c++ qt

我有一个 QListView 并想要实现拖放以让用户将列表中的项目移动到他/她想要的顺序。我的代码摘录是

  ui.lstViewBodyFiles->setDragEnabled(true);
  ui.lstViewBodyFiles->setDropIndicatorShown(true);
  ui.lstViewBodyFiles->setAcceptDrops(true);
  ui.lstViewBodyFiles->setSelectionMode( QAbstractItemView::SingleSelection);
  ui.lstViewBodyFiles->setDragDropMode( QAbstractItemView::InternalMove);
Run Code Online (Sandbox Code Playgroud)

上面的代码删除了这些项目而不是在内部移动它们。

Windows 10 上的 Qt 5.3.2。

i k*_*ing 0

您需要设置DragDropOverwriteMode(false)。