Unsolved Drag and Drop hidden columns workaround in treeview?
-
I have a treeview that is using a proxy to hide one of the columns. The tree view has an drag and drop mode set to InternalMove. When I drag and Drop an item the hidden row's item becomes null.
This looks to be a known issue with the standardItemModel and the devs dont want to change it:
https://bugreports.qt.io/browse/QTBUG-30242They did give a workaround as to override the selectedIndexes() in the view
class MyTreeView : public QTreeView { protected: QModelIndexList selectedIndexes() const { return selectionModel()->selectedIndexes(); } };
However in my view it does not help the hidden column issue at all
class HiddenTreeView(QtWidgets.QTreeView): def __init__(self, parent): super(HiddenTreeView, 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.setSortingEnabled(True) self.header().setStretchLastSection(True) self.header().setMinimumSectionSize(30) def selectedIndexes(self): return self.selectionModel().selectedIndexes()
Am I missing something here? The self.selectionModel().selectedIndexes() still only returns the visible only items.
Cheers
-
The purpose of the internal move drag and drop is to allow the user to create any hierarchy they need. I've allowed a custom context menu to create a parent on any item.
The hidden column was used in conjunction with a qdatawidgetmapper to manage a filter property in the proxy model. For now I can get around the issue by putting that data in a custom UserRole and making a itemDelegate for the qdatawidgetmapper. I was just hoping to not have to make the delegate to reduce the complexly of the code, but it seems to work atm.
I'd still like to know what the devs where referring too with their provided example.