I’m trying to use a QAbstractProxyModel (more specifically a QIdentityProxyModel) to present differently columned models for the same underlying model. So the source model doesn’t implement column-related stuff, but the proxy model does. It goes like this:
#!/usr/bin/env python3
#-*- coding: ISO-8859-1 -*-
from PyQt5 import QtCore, QtWidgets
class DummyModel(QtCore.QAbstractItemModel):
def rowCount(self, parent):
if parent.isValid():
return 0
return 10
def parent(self, index):
return QtCore.QModelIndex()
def index(self, row, column, parent):
if parent.isValid():
return QtCore.QModelIndex()
return self.createIndex(row, column)
class ProxyModel(QtCore.QIdentityProxyModel):
def __init__(self, model):
super().__init__()
self.setSourceModel(model)
def columnCount(self, parent):
return 3
def data(self, index, role):
if index.isValid() and role == QtCore.Qt.DisplayRole:
return 'Item #%d,%d' % (index.row(), index.column())
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
view = QtWidgets.QTreeView(self)
view.setModel(ProxyModel(DummyModel()))
self.setCentralWidget(view)
self.show()
self.raise_()
if __name__ == '__main__':
app = QtWidgets.QApplication([])
win = MainWindow()
app.exec_()
Unfortunately running this gives me this on the console:
NotImplementedError: QAbstractItemModel.columnCount() is abstract and must be
overridden
And nothing displays unless I define `columnCount` in the source model. So my
guess is that some method in QAbstractProxyModel *other than columnCount()*
calls sourceModel()->columnCount() directly instead of the proxy’s version. Is
that a bug ?
Best regards
Jérôme Laheurte
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ Interest mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/interest
