Hi,
I subclassed the code below from QTreeWidget to enable drag and drop. The problem is when i'm draging an item containing childrens, the childrens don't follow the parent on the drop. Is there a problem with mimeData?
Also, is there a way to obtain the index of the parent where I make the drop?
Thanks
{
QModelIndexList liste=selectedIndexes();
QMimeData *mimeData
= model
()->mimeData
(liste
);
drag->setMimeData(mimeData);
drag->setHotSpot(event->pos() - rect().topLeft());
Qt::DropAction dropAction = drag->start( Qt::MoveAction);
if (dropAction == Qt::MoveAction) {
model()->removeRows(liste[0].row(),liste.size(),liste[0].parent());
}
}
{
e->setDropAction(Qt::MoveAction);
e->accept();
}
void QMyTreeWidget::mouseMoveEvent(QMouseEvent *event)
{
QModelIndexList liste=selectedIndexes();
QMimeData *mimeData = model()->mimeData(liste);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setHotSpot(event->pos() - rect().topLeft());
Qt::DropAction dropAction = drag->start( Qt::MoveAction);
if (dropAction == Qt::MoveAction) {
model()->removeRows(liste[0].row(),liste.size(),liste[0].parent());
}
}
void QMyTreeWidget::dropEvent(QDropEvent *e)
{
QTreeWidget::dropEvent(e);
e->setDropAction(Qt::MoveAction);
e->accept();
}
To copy to clipboard, switch view to plain text mode
Bookmarks