Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Drag and Drop internal move bug creating additional rows with sort enabled.
Forum Updated to NodeBB v4.3 + New Features

Drag and Drop internal move bug creating additional rows with sort enabled.

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 412 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.
  • alomA Offline
    alomA Offline
    alom
    wrote on last edited by
    #1

    I've seem to run into a drag and drop bug using an internal move event that causing the model to add additional rows and offset column data.
    centos7, Qt 5.12

    in the example below I can replicate this every time by the following steps explicitly(DO NOT sort the Name column) :
    parent-3 should be the top node.

    1. select child item "4" from parent-3
    2. select child item "2" from parent-1
    3. drag and drop the two items over the parent-0

    this moves the two rows("4" & "2") and creates two more with no DisplayRole in the name column. The "Tag" & "Color" data from the two item rows are shifted to the additional rows.

    You can close and relaunched the application, now if you sort the Name column where parent-0 is the top node and try the step again, no additional rows are created.
    Can any one reproduced this? Is there something with the sort I'm missing or is this a bug?
    Cheers

    import sys
    from PySide2 import QtWidgets, QtGui
    from PySide2.QtCore import Qt
    
    class SnippetTreeView(QtWidgets.QTreeView):
    
        def __init__(self, parent=None):
            super(SnippetTreeView, self).__init__(parent)
            self.setContextMenuPolicy(Qt.CustomContextMenu)
            self.setDragEnabled(False)
            self.setDragDropOverwriteMode(False)
            self.setDragDropMode(QtWidgets.QAbstractItemView.InternalMove)
            self.setAlternatingRowColors(True)
            self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
            self.header().setStretchLastSection(True)
            self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
    
    
    def create_tag_color_items():
        item_tag = QtGui.QStandardItem('tag')
        item_tag.setDropEnabled(False)
        item_color = QtGui.QStandardItem('color')
        item_color.setDropEnabled(False)
        return item_tag, item_color
    
    
    def add_items(model):
        headers = [
            'Name',
            'Tag',
            'Color',
        ]
    
        model.setHorizontalHeaderLabels(headers)
        model.setColumnCount(len(headers))
    
        for num in range(4):
            parent_item = QtGui.QStandardItem('parent-' + str(num))
            parent_item.setDropEnabled(True)
            item_tag, item_color = create_tag_color_items()
    
            for n in range(num + 2):
                child_item = QtGui.QStandardItem(str(n) )
                child_item.setDropEnabled(False)
                ch_item_tag, ch_item_color = create_tag_color_items()
                parent_item.appendRow([child_item, ch_item_tag, ch_item_color])
    
            model.appendRow([parent_item, item_tag, item_color])
    
    
    if __name__ == '__main__':
        app = QtWidgets.QApplication(sys.argv)
        tree = SnippetTreeView()
        tree.setSortingEnabled(True)
        model = QtGui.QStandardItemModel()
        add_items(model)
        tree.setModel(model)
        tree.expandAll()
        tree.show()
        rec = app.exec_()
        sys.exit(rec)
    
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Looks like a bug, it happens also with PySide2 5.15.0

      Can you reproduce that with the C++ equivalent of your code ?

      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
      • alomA Offline
        alomA Offline
        alom
        wrote on last edited by
        #3

        Hi @SGaist ,
        Don't have 5.15 installed but I did submit a report though pyside and it was bumped to the main qt :
        https://bugreports.qt.io/browse/QTBUG-85324

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

          Thank you !

          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

          • Login

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