Qt-interest Archive, October 2007
Moving an item in a QAbstractItemModel
Message 1 in thread
Hi,
If I have my own itemmodel and a QTreeView showing it, what's the best
way to signal that an item has moved in the tree?
Consider a tree like this:
A -> B -> C -> D -> E
(ie: each node has one parent and one child)
Let's say that D moves so it's also a child of A. At the moment I do
this by beginRemoveRows(C, 1), endRemoveRows(), then beginInsertRows on
A. This works. The problem is selections. If the user had 'E' selected
prior to the move, it will be deselected after moving. The view also
forgets the expanded status of the items.
Is there some way to preserve persistent indexes when you're moving rows
around like this?
--
[ signature omitted ]