Unsolved How to allow only QAbstractView::AboveItem and BelowItem dragevents in a QTreeWidgetclass and get the source position and destination position
-
I'm currently using a custom qt widget class to accomplish this so far. I've been able to use the following code in order to restrict above and below events only, (reorder) and avoid moving items to top level.
void CustomTreeWidget::dropEvent(QDropEvent *event) { QModelIndex index = indexAt(event->pos()); QTreeWidgetItem* item = itemAt(event->pos()); DropIndicatorPosition position = dropIndicatorPosition(); if( !index.isValid() ) return; if( position != QAbstractItemView::AboveItem && position != QAbstractItemView::BelowItem ){ return; } QTreeWidget::dropEvent(event); }
But I'm not sure how to extract both source and destination position. It isn't even very clear what event-pos() refers to in every context.
event->source()
gives a QObject, but that isn't comparable to QTreeWidgetItems, and I'm not sure how to actually extract the widgetitem or position from the source.