It looks like your example is trying to loop through the whole model and
update the flags on every item, every time a click happens?

There are a couple ways you could solve this. You are in control of the
items you create in your view. So you could just set the flags properly on
them at creation time. But if you are basing the criteria on the name, and
you feel the name can change which would change the availability of
dropping then that may not work since you would then need to update the
flags on the item each time the data changes on items.

If you were using a view + model approach, the model has a flags() virtual
method that can be reimplemented to dynamically answer the question of what
flags an item has at any time.

But with the QTreeWidget, yes you could subclass it and implement
dragEnterEvent(). This would get called when an item enters the view. You
would need to inspect what is being dragged in to accept or ignore if you
allow it. Then you could implement the dragMoveEvent() to keep answering
yes or no as the item is moved over different parts of the view. It would
reject the event if it isn't over the parts you want.

So yes, the most complicated approach would be to implement the events. The
easiest approach would be to try and manage the flags when items are
created. Or switch to a QTreeView and model and implement flags() on the
model.

One thing I don't remember if I have tried is to call model() on your
QTreeWidget to get the abstract model instance, and then patching it's
flags() method and setting the model back on the view with setModel(). It
may not work since it was not originally  a python model.

Justin

On Fri, Apr 7, 2017, 12:26 AM Rudi Hammad <[email protected]> wrote:

> Hello,
>
> I have 2 tree widgets. I drag items from the tree on the right side. I
> want that the item named "container", once dropped in the left side tree,
> will become the only item that can
> receive drops. This is my first attempt. It is all setup to execute:
>
> https://pastebin.com/3QTU9rBX
>
> I guess that the problem is item dropped is taking the properties of the
> treewidget, so all the items can recieve drops.
>
> The only way that I can think of is creating my own QTreeWidget class and
> override methods such as dropEvent(), but isn“t that to complicated?
> Because I will also have to do mouse events,
> then get the QPoint on the widget, check which row it is, take out item,
> insert item etc...
> I just wonder if there is a simpler way before going crazy writing my own
> class. All I want is that the item "container" could receive drops in the
> left tree widget.
>
> Thanks
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/a31036f7-55ad-4b5c-9431-6d692dc8719e%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/a31036f7-55ad-4b5c-9431-6d692dc8719e%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2X_9oWBnBDpYHW6FavzY_YZ1qZi7WeeC3ckpRT%3D-xW1Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to