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
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a31036f7-55ad-4b5c-9431-6d692dc8719e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If you now have the drop position from the QDropEvent, then you should be able to inspect the item under the position via itemAt
http://doc.qt.io/qt-4.8/qtreewidget.html#itemAt
From there you can choose how you want to insert
Justin
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dbe817a4-5b86-480f-8e85-6073b1c2e88b%40googlegroups.com.
If you now have the drop position from the QDropEvent, then you should be able to inspect the item under the position via itemAt
http://doc.qt.io/qt-4.8/qtreewidget.html#itemAt
From there you can choose how you want to insert
Justin
On Sat, Apr 8, 2017, 4:10 AM Rudi Hammad <rudih...@gmail.com> wrote:
--
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+unsub...@googlegroups.com.
Thanks Justinn, that was it.
I guess that the next step is to be able to insert it before or after. The treeWidget by default highlights a line under or above, to indicate where the insertion will be done.
At the moment myInserted item is taking the place of the one that is dropped one. But I guess that it won´t be simple to do, since I will have to create methods to mimic this behavior?
My other question is if I am doing right the dropEvent(), because all I am doing is creating a new item and copying the text of the item in the left. I will also copy the data stored as userRole.
But is this a real drag and drop? I am just creating a newItem and copying the text and data of the item selected in the left.
R
El sábado, 8 de abril de 2017, 4:01:21 (UTC+1), Justin Israel escribió:
If you now have the drop position from the QDropEvent, then you should be able to inspect the item under the position via itemAt
http://doc.qt.io/qt-4.8/qtreewidget.html#itemAt
From there you can choose how you want to insert
Justin
On Sat, Apr 8, 2017, 4:10 AM Rudi Hammad <rudih...@gmail.com> wrote:
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dbe817a4-5b86-480f-8e85-6073b1c2e88b%40googlegroups.com.
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/830582ed-cbce-4d87-87f6-ef2d4ba5038f%40googlegroups.com.
Stepping back a sec to your previous questions and goal, did you actually want to customise the drip behavior beyond just filtering what can and can't be dropped?
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1092dfe8-3c55-4f95-8300-9d8073baae06%40googlegroups.com.
To get a visual reference I tried to do:
self.setDropIndicatorShown(True)
When I active this in QtDesigner, you see the line were it is going to be inserted. I am not sure why it is not working here
R
You could also have your drop insert between two items of the drop happened in the spacing between them. You currently have logic where if the drop was not on an item it will just append it. Add a little spacing to your tree widget between items and handle the case where it's between two items.
--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5eb72a6f-6dfe-4795-8a3f-3df48c2a19c5%40googlegroups.com.
You could also have your drop insert between two items of the drop happened in the spacing between them. You currently have logic where if the drop was not on an item it will just append it. Add a little spacing to your tree widget between items and handle the case where it's between two items.
On Tue, Apr 11, 2017, 12:04 AM Rudi Hammad <rudih...@gmail.com> wrote:
Okey, I think it is working properly now--
https://pastebin.com/Nsf0JNU5
I think it works, but is no very precise to get it exactly were you want, because the items are too small (and I want them small).To get a visual reference I tried to do:self.setDropIndicatorShown(True)
When I active this in QtDesigner, you see the line were it is going to be inserted. I am not sure why it is not working here
R
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+unsub...@googlegroups.com.
ok, but what you mean with "add spacing between items". Is this a treeWidget flag or something that will separate the items with some amount of pixels?
I am not sure to understand
R
El lunes, 10 de abril de 2017, 20:23:50 (UTC+1), Justin Israel escribió:
You could also have your drop insert between two items of the drop happened in the spacing between them. You currently have logic where if the drop was not on an item it will just append it. Add a little spacing to your tree widget between items and handle the case where it's between two items.
On Tue, Apr 11, 2017, 12:04 AM Rudi Hammad <rudih...@gmail.com> wrote:
Okey, I think it is working properly now--
https://pastebin.com/Nsf0JNU5
I think it works, but is no very precise to get it exactly were you want, because the items are too small (and I want them small).To get a visual reference I tried to do:self.setDropIndicatorShown(True)
When I active this in QtDesigner, you see the line were it is going to be inserted. I am not sure why it is not working here
R
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5eb72a6f-6dfe-4795-8a3f-3df48c2a19c5%40googlegroups.com.
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4dba28f7-e525-481a-a905-6ece9cfb5f5f%40googlegroups.com.