Make QTreeWidgetItem unique among siblings

2019-07-13 16:06发布

问题:

Is there some way to make sure that updating an existing QTreeWidgetItem or inserting a new one ensures that the item is unique among its siblings based on the value of a single column?

I have tried to do something like this with a QTreeView and my own custom model and have gotten it to work, but some advanced features like moving items with drag and drop are eluding me. I figure, the QTreeWidget and QTreeWidgetItem classes ought to get more of this type of stuff for free and ought to cause me fewer headaches throughout. However, I still need to be able to guarantee uniqueness if I go the QTreeWidget route. Can this be done? If so, how?

NOTE:

I am using PySide, but I marked this question as PyQt as well since most solutions cross over between the two without much fuss.