Trying_hard
Trying_hard

Reputation: 9501

PYQT4 Cell color

I am trying to set a color to a cell.

This is a small sample of my code:

self.tableWidget.setItem(1,8,QtGui.QTableWidgetItem("test)) # this works fine

I have tried to

self.tableWidget.item(1,8,QtGui.QTableWidgetItem.setBackgroundColor("NOT SURE HERE")) # want cell to red

What is the best way I can get the cell the color of red and still see the word "test"

Upvotes: 0

Views: 51

Answers (1)

hackyday
hackyday

Reputation: 1329

Instantiate a QTableWidgetItem and set the color first:

item = QtGui.QTableWidgetItem("test")
item.setBackground(QtCore.Qt.red)
self.tableWidget.setItem(1,8,item)

Upvotes: 1

Related Questions