QAbstractIItemModel for QTreeView with movable items
-
Hi!
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 ?
http://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.htmland
http://doc.qt.io/qt-5/model-view-programming.html#model-subclassing-referenceIf 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)
https://doc.qt.io/archives/4.6/model-view-dnd.html -
Tnx, mrjj!
http://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
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 -
@Harb said in QAbstractIItemModel for QTreeView with movable items:
Hi
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.