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!
table.horizontalHeader()->setStretchLastSection(true);
table.
setHorizontalHeaderLabels(QStringList() <<
"Sort Items by Dragging");
table.setDragEnabled(true);
table.setAcceptDrops(true);
table.setDropIndicatorShown(true);
const char * labels[] = { "Item D", "Item B", "Item C", "Item E", "Item A" };
for (int i=0; i < 5; ++i)
{
item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled);
table.setItem(0, i, item);
}
table.show();
return app.exec();
QApplication app(argc, argv);
QTableWidget table(5, 1);
table.horizontalHeader()->setStretchLastSection(true);
table.setHorizontalHeaderLabels(QStringList() << "Sort Items by Dragging");
table.setSelectionMode(QAbstractItemView::SingleSelection);
table.setDragEnabled(true);
table.setAcceptDrops(true);
table.setDropIndicatorShown(true);
const char * labels[] = { "Item D", "Item B", "Item C", "Item E", "Item A" };
for (int i=0; i < 5; ++i)
{
QTableWidgetItem * item = new QTableWidgetItem(labels[i]);
item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled);
table.setItem(0, i, item);
}
table.show();
return app.exec();
To copy to clipboard, switch view to plain text mode
Bookmarks