I have a QTreeWidget which I have setup like so...
ModelTreeWidget::ModelTreeWidget(QWidget *parent):QTreeWidget(parent), mpModelStruct(nullptr), mpModeldragging(nullptr), mpBufferModel(nullptr), mpModelCurrent(nullptr)
{
setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed);
setColumnCount(1);
setSelectionMode(QAbstractItemView::SingleSelection);
setDragEnabled(true);
viewport()->setAcceptDrops(true);
setDropIndicatorShown(true);
setDragDropMode(QAbstractItemView::DragDrop);
setDefaultDropAction(Qt::MoveAction);
}
I've also overwritten my drop event, but it's fairly innocuous:
void ModelTreeWidget::dropEvent(QDropEvent* event)
{
QTreeWidget::dropEvent(event);
}
Supported action is MoveAction:
Qt::DropActions ModelTreeWidget::supportedDropActions() const
{
return Qt::MoveAction;
}
Each item has the flags:
Qt::ItemFlags ModelTreeWidget::getTreeItemFlags() const
{
return (Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
}
Now when I populate my tree widget with items, I can drag one item over another, and it becomes added as a child to the item I dragged onto. However when I try to drag an item between two other items, I don't get an indicator (which I think should be a line) between the two rows. I just get the not allowed indicator.
My question is, how do I enable insertion of an item between two other items using drag and drop for QTreeWidget?
Edit: I setup my tree root using the following code:
QTreeWidgetItem* rootId = new QTreeWidgetItem((QTreeWidget*)0, QStringList(currentModel->name));
QVariant v = qVariantFromValue((void *) currentModel);
rootId->setData(0, Qt::UserRole, v);
rootId->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
insertTopLevelItem(0, rootId);
While each child of my root is setup as the following:
QTreeWidgetItem *item = new QTreeWidgetItem(parent, QStringList(tempModel->name));
QVariant v = qVariantFromValue((void *) tempModel);
item->setData(0, Qt::UserRole, v);
item->setFlags(getTreeItemFlags());
parent->addChild(item);