Hi,

I am working on drag and drop in QListView. For the help i am referring to Qt example puzzle in itemviews folder. Now the problem lies when the list view is in IconMode. Let me depict it:-

Capture.PNG

Now if i drag the item in the center of two items like shown in picture, its returning invalid index. Now while dropping i want to get the index of either left item or right. From Qt documentation what i got is :-

"When a drop occurs, the model index corresponding to the parent item will either be valid, indicating that the drop occurred on an item, or it will be invalid, indicating that the drop occurred somewhere in the view that corresponds to top level of the model.

int beginRow;

if (row != -1)
beginRow = row;
We initially examine the row number supplied to see if we can use it to insert items into the model, regardless of whether the parent index is valid or not.

else if (parent.isValid())
beginRow = parent.row();
If the parent model index is valid, the drop occurred on an item. In this simple list model, we find out the row number of the item and use that value to insert dropped items into the top level of the model.

else
beginRow = rowCount(QModelIndex());
When a drop occurs elsewhere in the view, and the row number is unusable, we append items to the top level of the model."

But this applies only for QListView in listmode.

If i put my mouse pointer in between two items its giving invalid index. How should i handle that. Please help me in this regard.

Thank you very much.