PDA

View Full Version : QTreeView drag & drop support for complete branch



Kadersin
11th May 2020, 22:11
Hello all,

After a long and frustrating time searching for answers on how to create a QTreeView working on a QAbstractItemModel that supports drag & drop, I always found half working examples. I finally found an example that worked:
http://www.java2s.com/Code/Cpp/Qt/QTreeViewdraganddrop.htm

I was SO happy! But, it was missing one crucial step: It did not copy/move entire branch. It could work with many nodes at once (multi-selection), but it did not copy the children of those nodes.

I coded the extra step and I wanted to share it with you, so nobody would need to suffer like I did.

So, here's the code to drag and drop any nodes and their children inside a QTreeView!

BTW, it is not a professional software, as it do not catch all errors, but it will do what was advertised!

:)