I've tried to do something like that recently. In mousePressEvent() function execute a new drag object and
in dropEvent() function handle with replacing the item.
Following code may help.
event->acceptProposedAction();
}
event->acceptProposedAction();
}
dropingOn = this->itemAt(event->pos());
int dropingIndex = this->indexOfTopLevelItem(dropingOn);
this->takeTopLevelItem(this->indexOfTopLevelItem(draggingItem));
int index = this->indexOfTopLevelItem(dropingOn);
if(index < dropingIndex) index++;
this->insertTopLevelItem(index, draggingItem);
}
if(event->button()==Qt::LeftButton) {
draggingItem = this->itemAt(event->pos());
drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction);
event->accept();
}
}
void Tree::dragMoveEvent(QDragMoveEvent * event) {
event->acceptProposedAction();
}
void Tree::dragEnterEvent(QDragEnterEvent * event ) {
event->acceptProposedAction();
}
void Tree::dropEvent(QDropEvent * event ) {
dropingOn = this->itemAt(event->pos());
int dropingIndex = this->indexOfTopLevelItem(dropingOn);
this->takeTopLevelItem(this->indexOfTopLevelItem(draggingItem));
int index = this->indexOfTopLevelItem(dropingOn);
if(index < dropingIndex) index++;
this->insertTopLevelItem(index, draggingItem);
}
void Tree::mousePressEvent(QMouseEvent *event) {
if(event->button()==Qt::LeftButton) {
draggingItem = this->itemAt(event->pos());
QDrag *drag = new QDrag(this);
drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction);
event->accept();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks