JSPoly
6th February 2007, 22:32
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
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();
}
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
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();
}