I am trying to implement a reorderable listview. I created a QListView in my form an set the following settings:
d->widget->ui.listView_searches->setDragEnabled(true);
d->widget->ui.listView_searches->setAcceptDrops(true);
d->widget->ui.listView_searches->setDropIndicatorShown(true);
d->widget->ui.listView_searches->setSelectionMode(QAbstractItemView::SingleSelection);
d->widget->ui.listView_searches->setSelectionBehavior(QAbstractItemView::SelectRows);
d->widget->ui.listView_searches->setDragDropMode(QAbstractItemView::InternalMove);
d->widget->ui.listView_searches->setDefaultDropAction(Qt::MoveAction);
In the model I reimplemented
Qt::DropActions Websearch::EnginesModel::supportedDropActions() const {
return Qt::MoveAction;
}
Qt::ItemFlags Websearch::EnginesModel::flags(const QModelIndex &index) const {
if (index.isValid())
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | QAbstractItemModel::flags(index);
else
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled | QAbstractItemModel::flags(index);
}
Further I implemented insert-, remove- and moveRows.
When I drag an item in the list I see the visual drop indicator. When releasing the mouse button the dragged item gets removed and a new default item gets inserted. What am I doing wrong?