PDA

View Full Version : Preserving structure in QTreeView drag and drop



Tito Serenti
12th February 2009, 03:18
Hi, I have reimplemented my own QTreeView and my own model, and enabled drag and drop following the example in the documentation (using text meta data). The problem I'm having is in preserving the structure of the tree as I drag and drop the items (from the same tree). In the documentation the example simply drops the list of items, but the parent-child relationship is lost. How do I insert the dropped items and preserve their tree structure?

I tried accessing the selection in the tree instead of passing the info via meta data, because then I could just iterate the tree and insert the items that are selected (since the selected items are the ones being dragged and dropped. But selectionModel() does not return items in their proper order, so the folders are all grouped together, the files are grouped together and I can't get the parent-child relationship from that either.

Any ideas?

Tito Serenti
14th February 2009, 04:39
Never mind, I found a solution. I used a recursive function to get the list of selected items and then a recursive function to insert them when dropped (the drag and drop is limited to the same tree).