PDA

View Full Version : How to detect drop is between two items or on one item in QTreeView?



derhexer
13th May 2013, 14:04
Hi,

i'm using QTreeView connected to a QStandardItemModel (which is based on sqlite database). I want support full drag and drop. So i have to know if a drop is released on one item or between two items. How can i detect this?

Thanks for any help and hint!

derhexer
13th May 2013, 18:56
I solved it...


bool MyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
if (parent.isValid())
{
QStandardItem *itemTo = itemFromIndex(parent);
if (row < 0) //dropped on item
qDebug() << "append as child to item: " << itemTo->data().toInt();
else //dropped between two items
{
QModelIndex insert = parent.child(row, column);
itemTo = itemFromIndex(insert);
qDebug() << "insert as sibling before: " << itemTo->data().toInt();
}
}
....
}