Hello everyone,
I found something very curious about QSortFilterProxyModel and I have trouble dealing with this :
Here is the situation :
I have a QTreeView with his model QStandardItemModel.
My QStandardItemModel contains some Customized QStandardItem.
self.listlabelGroupView = QTreeView(self.widget)
self.listlabelGroupView.setExpandsOnDoubleClick(Fa lse)
self.listlabelGroupView.setSelectionBehavior(QAbst ractItemView.SelectRows)
self.listlabelGroupView.setDragEnabled(True)
self.listlabelGroupView.setRootIsDecorated(False)
self.listlabelGroupView.setSortingEnabled(True)
self.listlabelGroupView.setFont(font)
self.listlabelGroupView.sortByColumn(1, Qt.AscendingOrder)self.listlabelGroupModel = QStandardItemModel(0,1)
self.listlabelGroupModel.setHorizontalHeaderLabels (["Name"])I want to get my Customized QStandardItem when I double click on the QTreeView with this code :self.filter = QSortFilterProxyModel()
self.filter.setFilterKeyColumn(0)
self.filter.setSourceModel(self.listlabelGroupMode l)
self.filter.setDynamicSortFilter(True)
self.listlabelGroupView.setModel(self.filter)
but it does not work, myItem has NoneType and I don't know why because when I don't use any filter, with the same code it works !a = self.listlabelGroupView.selectionModel().currentIn dex()
myItem = a.model().sourceModel().itemFromIndex(a)
I have also checked that the source model of the filter and my QStandardItemModel are the same object and it is only when I set the filter to my QTreeView that the QStandardItemModel "bugs".self.listlabelGroupView.setModel(self.listlabelGro upModel)
a = self.listlabelGroupView.selectionModel().currentIn dex()
myItem = a.model().itemFromIndex(a)
# myItem has type : CustomQStandardItem which is normal
Does anyone have any explanations to this behaviour ?
Bookmarks