[Interest] How to reorder QListView contents through Drag-N-Drop

Michael Jackson imikejackson at gmail.com
Tue Apr 3 19:03:23 CEST 2012


I have a QListView in my GUI. I would like to be able to use Drag-N-Drop to allow the user to move items with the list. I have checked some settings in QDesigner to enable this functionality but the issue I am having is that if the user drags a selection directly over another entry then the entry that got dropped on is removed and the selected item that was being dragged is put in its place. Is there a way (without subclassing a custom Model) to disable the dropping of one item on another?
  I am currently using a QStringListModel and it looks I need to subclass that model and implement the flags() method? 


Qt::ItemFlags DragDropListModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QStringListModel::flags(index);

if (index.isValid())
return Qt::ItemIsDragEnabled | defaultFlags; 
else
return Qt::ItemIsDropEnabled | defaultFlags;
}

Is this a correct understanding of the situation?


Thanks
Mike Jackson


More information about the Interest mailing list