I've actually done the manual approaches before with raw widgets, this is
partially because I think that the model/view approach is actually the best
way to handle this particular scenario, and partially because I want to
know more of the ins and outs of Qt's systems.  Mostly the former, but I do
like increasing my knowledge base :)

With that said, I did just get everything working without the cloning step,
and without subclassing QTreeView.  I basically added a flag to my model to
block item removals, set the flag in dropMimeData, and then check that flag
in removeRows, where I clear it if it was set and then skip the actual row
removal.  It still feels a bit hacky, but it works.  I think the next stage
is to subclass QTreeView.  That feels more clean all around, even if it is
a little more work :)

On Wed, Mar 11, 2015 at 5:12 PM, Justin Israel <justinisr...@gmail.com>
wrote:

> Ya actually there are a number of ways to work with drag and drop,
> depending on what classes you are using. Like you have said, there is
> dropMimeData on the model if you want to handle it there, and startDrag on
> the view if you want to handle it there, and then more manual approaches
> with starting your own drag in the mouse events.
>
>
> On Thu, Mar 12, 2015 at 1:08 PM Joe Weidenbach <scdr...@gmail.com> wrote:
>
>> Just an update; from my research, it looks like I need to subclass
>> QTreeView to do this.  The default implementation of startDrag from
>> QAbstractItemView apparently is what will delete the original item after
>> everything's said and done, which checks out with reading the source code
>> of qabstractitemview.cpp.  So far, I've made do with a raw QTreeView.  It
>> looks like I'll have to subclass that so I can override startDrag and not
>> have it remove the row.
>>
>> On Wed, Mar 11, 2015 at 3:41 PM, Joe Weidenbach <scdr...@gmail.com>
>> wrote:
>>
>>> I'm glad we're all on the same page.  Looking into Justin's mention of
>>> "taking" the item, I do see that functionality in the Convenience Widgets
>>> (QTreeWidget, etc), but not in QAbstractItemModel.  Same with Marcus'
>>> suggestion of moveRow(). I might be looking at the wrong documentation...(
>>> http://srinikom.github.io/pyside-docs/PySide/QtCore/
>>> QAbstractItemModel.html or http://qt-project.org/doc/
>>> qt-4.8/qabstractitemmodel.html).
>>>
>>> I haven't gone into beginMoveRows yet, mainly as in dropMimeData I don't
>>> have an index or parent for the original element (I think the model manages
>>> that internally), although I can get the data from it (I look up the
>>> element in my underlying data model using the serialization I put into the
>>> MimeData).  I'm doing the reordering exactly as Marcus described as well,
>>> although I'm currently inserting my cloned item.
>>>
>>> I think I could serialize the index data in mimeData to reconstruct the
>>> parent index in dropMimeData, that might be my next move so I can try
>>> working with beginMoveRows and see if it's any cleaner.
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to python_inside_maya+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/python_inside_maya/CAM33%3Da6U7RYaWUVBFaxCLuhzMzWAB%
>> 3DYU_UPOdg0A0CetR%2BH9KA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAM33%3Da6U7RYaWUVBFaxCLuhzMzWAB%3DYU_UPOdg0A0CetR%2BH9KA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0rK435D%2BC47gx1AgSJuRxhbm7ZfQSzKZnNzaeJgxpuqw%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0rK435D%2BC47gx1AgSJuRxhbm7ZfQSzKZnNzaeJgxpuqw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAM33%3Da4YST5%3DHTceZw8GyAf_erPzuA_FqmKA3wY-%3DXgmx8Ui3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to