[Qt-interest] Drag & Drop of hierachical items in a TreeView
Daniel Price
daniel.price at fxhome.com
Thu Nov 26 17:36:02 CET 2009
I'm trying to figure how to do drag and drop editing of hierarchical data within an QAbstractItemModel-derived adaptor within a QTreeView.
Single items with no children seem to work fine (I'm only interested in moving data, not copying it). However if I move an item with children, the children are lost and I'm not sure how I can preserve them as the dropMimeData() virtual only gives me the mime data and drop target.
I can think of same ways around this but I don't know what the 'best practice' solution would be:
1) Encode the QModelIndex of the original item into the mime data (QDataStream) and use it to recursively iterate through and reconstruct the tree in the drop location (it seems that the source items are not removed until after dropMimeData() is called so the index should remain valid).
2) Cache the source model index somewhere when a drag is initiated (mimeData()?) and do the above.
Any suggestions? Has anyone got this working?
Daniel Price
Software Engineer
FXhome Limited
________________________________
This email is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. If you are not the intended recipient please notify the sender. Please delete the message from all places in your computer where it is stored. You should not copy the email or use it for any purpose or disclose its contents to any other person.To do so may be unlawful. Email is an informal means of communicating and may be subject to data corruption accidentally or deliberately. For this reason it is inappropriate to rely on advice contained in an email without obtaining written confirmation of it first.
FXhome Limited is a limited company registered in England and Wales. Registered number: 04172812. Registered office: The Henderson Business Centre, Ivy Road, Norwich, Norfolk, NR5 8BF, U.K.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091126/e592e579/attachment.html
More information about the Qt-interest-old
mailing list