QAbstractIItemModel for QTreeView with movable items
I want to implement QAbstractItemModel, so that it will provide data for QTreeView. So, internal data is organized to the tree structure. Also I want to make QTreeView interactive, so user could move items from parent to another parent, up and down. Now I am a little bit confused what methodes of QAbstractItemModel I should implement for that. Should I implement drag/drop methodes? Or moveRows is enought?
Hi and welcome
Did you see this example ?
If you just want to be able to rearrange the items, maybe the default drag and drop is enough.
Its off pr default.
old doc ( sorry my goggle foo failed)
This is the new doc where drag and drop is described. Well, I played around a little bit with QTreeView and QAbstractItemModel, and I was surpirsed that when I do drag/drop opeartions QAbstractItemModel::insertRows and QAbstractItemModel::removeRows are invoked. I thought that QAbstractItemModel::moveRows would. I don't understand how should I implement my internal tree data structure changes inside these methodes? With moveRows it would be quite straightforward
they both seems to be part of "move items" feature.
For removeRows , docs says
"WThe base class implementation does nothing and returns false."
So maybe you can just use moveRows and it works.