Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Items in QTreeView being replaced by QStandardItem when dragging

Items in QTreeView being replaced by QStandardItem when dragging

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • WoGiW Offline
    WoGiW Offline
    WoGi
    wrote on last edited by
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      WoGiW 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

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

        WoGiW Offline
        WoGiW Offline
        WoGi
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you re-implement a model yourself ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • WoGiW Offline
            WoGiW Offline
            WoGi
            wrote on last edited by
            #5

            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)
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved