I'm trying to make a treewidget that can change children between parents with the drag and drop method, but a children can never be turned in a parent. Right now this is my class:
class Tree(QTreeWidget):
def __init__(self, parent=QWidget):
QTreeWidget.__init__(self,parent)
self.setAcceptDrops(True)
self.setDragEnabled(True)
self.setDropIndicatorShown(True)
self.setEditTriggers(QAbstractItemView.AllEditTriggers)
self.setDragDropMode(QAbstractItemView.InternalMove)
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
def dragMoveEvent(self, event):
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
def dropEvent(self, event):
event.setDropAction(QtCore.Qt.MoveAction)
event.accept()
target_item= self.itemAt(event.pos())
if target_item:
object_name= target_item.text(0)
if self.currentItem().parent():
parent_item= self.currentItem().parent()
parent_name = parent_item.text(0)
print("Número de Serie:", self.currentItem().text(0))
print("Solto no:",object_name)
print("Codigo de barras:",parent_name)
else:
print("Objeto de destino: ", object_name)
else:
print("Solto fora de qualquer")
So i upgrade my code and i tried to print were the child is droped and its all working but the same problem still stand´s the child when is dragged it always disapear from de treewidget and i dont know why.
Every help is welcome, thanks