View Full Version : QTreeView QAbstractItemModel drag drop
Qiieha
31st October 2012, 13:19
Hi I use a custom QTreeView and QAbstractItemModel and want to implement drag drop.
I followed the docu and reimplemented the needed methods. I just want to achieve internal move of items within a parent. The problem is that I can't drop an item between other items. I just can drop an item on another item.
There is no drop indicator between elements. What's wrong, please help me.
Qiieha
1st November 2012, 11:04
Hi
I can append the dragged item as sibling on my own in dropMimeData(). So it is not important that there is a dropindicator between the items...
But I have another problem:
My QMimeData Object contains the internalPointer of my the dragged item. And the internal pointer has a QDomNode member.
So have all things I need. The parent-Node, the parent-Index, the child-Node, the childI-index, the sibling-index and subling-Node. In dropMimeData() I append the the dragged node with the following code:
siblingNode.parentNode().removeChild(newNode);
siblingNode.parentNode().insertAfter(newNode,sibli ngNode);
The underlaying xml doc is now correct, but the QAbstractItemModel doesn't update. I tried everything beginRemoveRows() and endRemoveRows(), beginInsertRows(), endInsertRows().
I emit dataChanged() with the parent index, but nothing is updated.
What I have to do? Do I have reimplement insertRows and removeRows. I read that this is not necessary if I remove and insert data by myself...
thank you
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.