I'm new in Python and PYQT and I'm trying to change the background color of the cells of my Tableview based on the value of the cell. Using some examples I read here, I came up with this code.
def openWindow(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_Variacao_Diaria()
self.ui.setupUi(self.window)
self.window.show()
file = r'C:/Desktop/Teste_base.xlsx'
df = pd.read_excel(file)
df2 = pd.pivot_table(df,index=["Date"],columns=["Club"])
df3 = pd.DataFrame(df2.to_records())
headers = list(df3)
self.ui.t_var.setColumnCount(0)
for c in range(0,len(df3.columns)):
self.ui.t_var.insertColumn(c)
self.ui.t_var.setRowCount(0)
for l in range(0,len(df3)):
self.ui.t_var.insertRow(l)
for c in range(0,len(df3.iloc[l])):
self.ui.t_var.setItem(l, c, QTableWidgetItem(str(df3.iloc[l][c])))
self.ui.t_var.setHorizontalHeaderLabels(headers)
if df3.iloc[l][c] < 100:
self.ui.t_var.item(l,c).setBackground(QtGui.QColor(125,125,125))
The problem is that when I put this
if df3.iloc[l][c] < 100: self.ui.t_var.item(l,c).setBackground(QtGui.QColor(125,125,125))
my code stops in the first cell and does not fill the rest of my TableView with the data. How can I make to continuous with the looping??