2

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?

ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103
  • A while ago I answered a similar question only it was in PyQt. [Check it out](http://stackoverflow.com/questions/40250771/editable-reorderable-by-drag-and-drop-qt5-qtreeview-example/40421386#40421386). – Dmitry Apr 10 '17 at 08:58
  • @ManuelSchneid3r did you find a solution for this? – user31208 Jan 13 '19 at 16:48

0 Answers0