4

I have a class that extends from QTreeView that has a data model that extends from QAbstractItemModel and I want to drag an item to it.

My problem is this, when I am dragging, I have the drag indicator shown, and its shows either a rectangle to drop on the item, or a line to drop between the items. When I receive the dropMimeData in my data model though, I see no way to retrieve this data. I noticed there is a dropIndicatorPosition on the QAbstractItemView, but it is protected. So my question is, how can I know in dropMimeData if the drop is on the item, before it or after it?

steprobe
  • 1,659
  • 3
  • 17
  • 32

1 Answers1

4

Ok, I found the answer:

bool MyModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
                  int row, int column, const QModelIndex &parent)

If the QModelIndex is valid (not parent.row(), parent.column() of -1) then it is being dropped on that object as its parent and its up to me to figure out where to put it in the model.

If it is not valid, then the row and column is not -1, and I have an invalid model index and the object is being inserted at that position.

This was in the qt docs "Using Drag and Drop with Item Views" - I had only seen the general drag/drop documentation.

eric
  • 7,142
  • 12
  • 72
  • 138
steprobe
  • 1,659
  • 3
  • 17
  • 32