I'm trying to learn how to do drag and drop. I wrote a simple program which is supposed to permit the user to sort items in a table. It almost does what I want, but when the user drops items at new locations, copies are made. I can't figure out how to change it so that the original item is deleted in addition to the copy being made. Can anyone offer me some assistance? Thanks!

Qt Code:
  1. QApplication app(argc, argv);
  2.  
  3. QTableWidget table(5, 1);
  4. table.horizontalHeader()->setStretchLastSection(true);
  5. table.setHorizontalHeaderLabels(QStringList() << "Sort Items by Dragging");
  6.  
  7. table.setSelectionMode(QAbstractItemView::SingleSelection);
  8. table.setDragEnabled(true);
  9. table.setAcceptDrops(true);
  10. table.setDropIndicatorShown(true);
  11.  
  12. const char * labels[] = { "Item D", "Item B", "Item C", "Item E", "Item A" };
  13. for (int i=0; i < 5; ++i)
  14. {
  15. QTableWidgetItem * item = new QTableWidgetItem(labels[i]);
  16. item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled);
  17. table.setItem(0, i, item);
  18. }
  19.  
  20. table.show();
  21. return app.exec();
To copy to clipboard, switch view to plain text mode