qt: pyqt: QTreeView internal drag and drop almost working… dragged item disappears

前端 未结 1 971
抹茶落季
抹茶落季 2021-01-06 04:20

I almost have a completely working drag and drop re-order within a QTreeView. Everything seems to be ok except the dropped object never appears (though I can refer

相关标签:
1条回答
  • 2021-01-06 05:17

    This doesn't solve all the problems, but changing dropMimeData() to the following will at least allow moving leaf items.

        self.beginInsertRows(parentIndex, row, row)
        parentIndex.internalPointer().add_child_obj(Branch(item.get_name(), item.get_value(), parent), row)
        self.endInsertRows()
    

    A drag-drop operation is effectively two steps, an insert (done in dropMimeData) and a remove (done automatically by the Move drag operation). The changes above insert a new item rather than trying to insert an item which is already in the model and which will be removed from the old location after the insert occurs.

    0 讨论(0)
提交回复
热议问题