Reputation: 1466
I have a QTreeWidget with what I thought all the proper settings setup in order to be able to reorder items by dragging them around. It can work, at times, but more often than not I drag an item into another one and it either disappears or becomes a child.
Is there anyway to prevent this from happening so you don't lose items you're trying to reorder? I figured you could achieve this within Qt Designer. I have dragDrop mode set to InternalMove and defaultDropAction set to MoveAction, but I'm not even certain of both of those are what I need to be adjusting.
Thanks in advance!
Upvotes: 3
Views: 3546
Reputation: 120578
You can add flags to individual tree widget items that control drag and drop behaviour (amongst other things). For instance, to prevent an item being a drop target, try something like this:
item = QTreeWidgetItem(parent)
item.setFlags(items.flags() & ~Qt.ItemIsDropEnabled)
For more details, see: Qt.ItemFlags
Upvotes: 4