I subclassed a QTreeWidget, set its dragDropMode to InternalMove and populated it with custom items, some of which can be dragged, others accept drops. The user can move items around the tree as expected. But I need to be notified of the change in the order of items and react appropriately. Unfortunately, there are no signals associated with the movement of items inside the tree that I could connect to.
I tried getting a handle to the QTreeWidget's underlying model(), then connecting to its rowsMoved signal, but it doesn't seem to be emitted during internal moves.
I reimplemented QTreeWidget's dropEvent(), but there's no way to determine the destination row index there.
The dropMimeData() event doesn't get called at all for internal moves, apparently.
Any other approach I could try? Thanks.
In the reimplemented dropEvent()
, you should be able to find the destination row index and item:
void
subclass::dropEvent(QDropEvent* event)
{
QModelIndex index = indexAt(event->pos());
if (!index.isValid()) { // just in case
event->setDropAction(Qt::IgnoreAction);
return;
}
QTreeWidgetItem* destination_item = itemFromIndex(index);
....
}