Items in QTreeView being replaced by QStandardItem when dragging



  • This post is deleted!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    That should already be the case if you are using the InternalMove drag & drop mode.



  • @SGaist Hey, thanks for your very prompt response.

    Just implemented the InternalMove as you suggested, however when the item is dropped, it still gets replaced by a fresh instance of a QStandardItem.


  • Lifetime Qt Champion

    Did you re-implement a model yourself ?



  • I used a QStandardItemModel.
    Heres a super stripped down version of my code:

    from PySide import QtGui, QtCore
    
    class QTreeViewCustom(QtGui.QTreeView):
        def __init__(self):
    
            super(QTreeViewCustom,self).__init__()
    
            self.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
            self.setDragEnabled(True)
            self.setDropIndicatorShown(True)
    
            self.dataModel = QtGui.QStandardItemModel()
            
            self.root = self.dataModel.invisibleRootItem()
            self.root.setDropEnabled(True)
    
            self.setModel(self.dataModel)
            self.setSelectionMode(QtGui.QAbstractItemView.SelectionMode.ContiguousSelection)
    
            #fill the tree with items
            for i in range(10):
                self.root.appendRow(testItem(str(i)))
    
    class testItem(QtGui.QStandardItem):
        def __init__(self,name):
    
            super(testItem,self).__init__()
            self.setText(name)
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.