<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Drag and Drop internal move bug creating additional rows with sort enabled.]]></title><description><![CDATA[<p dir="auto">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.<br />
centos7, Qt 5.12</p>
<p dir="auto">in the example below I can replicate this every time by the following steps explicitly(DO NOT sort the Name column) :<br />
parent-3 should be the top node.</p>
<ol>
<li>select child item "4" from parent-3</li>
<li>select child item "2" from parent-1</li>
<li>drag and drop the two items over the parent-0</li>
</ol>
<p dir="auto">this moves the two rows("4" &amp; "2") and creates two more with no DisplayRole in the name column. The "Tag" &amp; "Color" data from the two item rows are shifted to the additional rows.</p>
<p dir="auto">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.<br />
Can any one reproduced this? Is there something with the sort I'm missing or is this a bug?<br />
Cheers</p>
<pre><code>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)


</code></pre>
]]></description><link>https://forum.qt.io/topic/116007/drag-and-drop-internal-move-bug-creating-additional-rows-with-sort-enabled</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 21:44:17 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/116007.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 18 Jun 2020 00:59:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Drag and Drop internal move bug creating additional rows with sort enabled. on Sat, 01 Aug 2020 17:26:55 GMT]]></title><description><![CDATA[<p dir="auto">Thank you !</p>
]]></description><link>https://forum.qt.io/post/610048</link><guid isPermaLink="true">https://forum.qt.io/post/610048</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 01 Aug 2020 17:26:55 GMT</pubDate></item><item><title><![CDATA[Reply to Drag and Drop internal move bug creating additional rows with sort enabled. on Sat, 01 Aug 2020 17:19:19 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> ,<br />
Don't have 5.15 installed but I did submit a report though pyside and it was bumped to the main qt :<br />
<a href="https://bugreports.qt.io/browse/QTBUG-85324" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/browse/QTBUG-85324</a></p>
]]></description><link>https://forum.qt.io/post/610047</link><guid isPermaLink="true">https://forum.qt.io/post/610047</guid><dc:creator><![CDATA[alom]]></dc:creator><pubDate>Sat, 01 Aug 2020 17:19:19 GMT</pubDate></item><item><title><![CDATA[Reply to Drag and Drop internal move bug creating additional rows with sort enabled. on Fri, 10 Jul 2020 21:15:18 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Looks like a bug, it happens also with PySide2 5.15.0</p>
<p dir="auto">Can you reproduce that with the C++ equivalent of your code ?</p>
]]></description><link>https://forum.qt.io/post/606096</link><guid isPermaLink="true">https://forum.qt.io/post/606096</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 10 Jul 2020 21:15:18 GMT</pubDate></item></channel></rss>