I am new in pyqt4 and I can't figure out how to do this. I have a QtableWidget with data in it. I want to change some background color of the tableWidget's cells.
I tried self.tableWidget.item(3, 5).setBackground(QtGui.QColor(100,100,150)) and it returns this error:
AttributeError: 'NoneType' object has no attribute 'setBackground'
What should I do?
解决方案
You must first create an item in that place in the table, before you can set its background color.
self.tableWidget.setItem(3, 5, QtGui.QTableWidgetItem())
self.tableWidget.item(3, 5).setBackground(QtGui.QColor(100,100,150))
新手在使用PyQt4时遇到QTableWidget单元格背景色设置问题,错误提示'NoneType'对象无'setBackground'属性。解决方案是确保在设置背景色之前先在对应位置创建QTableWidgetItem。
2571

被折叠的 条评论
为什么被折叠?



