Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Qtablewidget's specific cells background color in pyqt

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?

like image 903
alperyazir Avatar asked Sep 19 '13 07:09

alperyazir


1 Answers

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))
like image 198
hackyday Avatar answered Sep 17 '22 20:09

hackyday