<div>I'm not sure if this is a bug or I'm just doing it wrong. If you use setItemDelegateForColumn on multiple columns only the last assigned delegate will actually be called. I have only run this code on PyQt 4.8.2.</div>
<div><br></div><div>Example:</div><div><div>import sys</div><div>from PyQt4 import QtCore, QtGui</div><div><br></div><div>class TestWidget(QtGui.QWidget):</div><div> def __init__(self, parent=None):</div><div> super(TestWidget, self).__init__(parent)</div>
<div> self.layout = QtGui.QVBoxLayout()</div><div> self.createTableView()</div><div> self.setLayout(self.layout)</div><div> def createTableView(self):</div><div> model = QtGui.QStandardItemModel(5, 5)</div>
<div> model.setHeaderData(0, QtCore.Qt.Horizontal, 'Column #0')</div><div> model.setHeaderData(1, QtCore.Qt.Horizontal, 'Column #1')</div><div> model.setHeaderData(2, QtCore.Qt.Horizontal, 'Column #2')</div>
<div> model.setHeaderData(3, QtCore.Qt.Horizontal, 'Column #3')</div><div> model.setHeaderData(4, QtCore.Qt.Horizontal, 'Column #4')</div><div> table = QtGui.QTableView()</div><div> table.setModel(model)</div>
<div> table.verticalHeader().setVisible(False)</div><div> delegate_0 = Column0Delegate()</div><div> table.setItemDelegateForColumn(0, delegate_0)</div><div> delegate_1 = Column1Delegate()</div>
<div> table.setItemDelegateForColumn(1, delegate_1)</div><div> delegate_2 = Column2Delegate()</div><div> table.setItemDelegateForColumn(2, delegate_2)</div><div> delegate_3 = Column3Delegate()</div>
<div> table.setItemDelegateForColumn(3, delegate_3)</div><div> self.layout.addWidget(table)</div><div><br></div><div>class Column0Delegate(QtGui.QItemDelegate):</div><div> def __init__(self):</div><div> super(Column0Delegate, self).__init__()</div>
<div> def paint(self, painter, options, index):</div><div> print 'Column0Delegate.paint()'</div><div><br></div><div>class Column1Delegate(QtGui.QItemDelegate):</div><div> def __init__(self):</div><div>
super(Column1Delegate, self).__init__()</div><div> def paint(self, painter, options, index):</div><div> print 'Column1Delegate.paint()'</div><div><br></div><div>class Column2Delegate(QtGui.QItemDelegate):</div>
<div> def __init__(self):</div><div> super(Column2Delegate, self).__init__()</div><div> def paint(self, painter, options, index):</div><div> print 'Column2Delegate.paint()'</div><div><br></div>
<div>class Column3Delegate(QtGui.QItemDelegate):</div><div> def __init__(self):</div><div> super(Column3Delegate, self).__init__()</div><div> def paint(self, painter, options, index):</div><div> print 'Column3Delegate.paint()'</div>
<div><br></div><div>def main(argv):</div><div> app = QtGui.QApplication(argv)</div><div> window = TestWidget()</div><div> window.show()</div><div> return app.exec_()</div><div><br></div><div>if __name__ == '__main__':</div>
<div> sys.exit(main(sys.argv))</div></div><div><br></div><div>According to itemDelegateForColumn the delegate is being assigned...</div><div><br></div><div><__main__.Column0Delegate object at 0x023106F0></div><div>
<__main__.Column1Delegate object at 0x02310738></div><div><__main__.Column2Delegate object at 0x02310780></div><div><__main__.Column3Delegate object at 0x023107C8></div><div><br></div><div>However when the program runs it only prints "Column3Delegate.paint()" when it should print all 4 of those messages. It appears that only the last assigned delegate is actually being called.</div>
<div><br></div><div>Am I doing something wrong here or is this a bug?</div><div><br></div><div>Thanks!</div><br>-- <br>Best Regards,<br>Kurt Schwarz<br>