PDA

View Full Version : Child items are lost on drop



justin123
29th May 2012, 00:29
I've run into a problem with QTreeView where child items are not being moved during a drop. It seems that reimplementing dragMoveEvent causes this to happen. It's supposed to read a user variable from the item being dragged and compare it to the item where it is going to be dropped. If they have the same value then it calls QTreeView's dragMoveEvent, otherwise it ignores the event. I'm doing this because Qt doesn't allow accepted mimeTypes to be set for each individual item (or does it?).


void ResourceView::dragMoveEvent(QDragMoveEvent *event)
{
QModelIndex index = indexAt(event->pos());

QDataStream stream( &event->mimeData()->data("resource/index"), QIODevice::ReadOnly);
int type;
int parentType =-1;

int r, c;

QMap<int, QVariant> v;
stream >> r >> c >> v;

parentType = index.data( Qt::UserRole+1).toInt();
type = v[Qt::UserRole+1].toInt();

if (parentType == type)
{
QTreeView::dragMoveEvent( event);
}
else
{
event->ignore();
}
}

The child items are moved when I completely comment this out. On the other hand, if I call QTreeView::dragMoveEvent( event) alone with the other stuff commented out in the function the problem still persists. What could be the issue?

justin123
30th May 2012, 13:55
It seems like the custom mime type I was using was causing the problem. Using the default mime type seem work. I'm just worried about foreign items being dragged in there.