Dynamic table in python

Asked

Viewed 725 times

2

I have a problem and I can’t identify the mistake.

I am creating a dynamic table in Python where it will be filled with database information. The problem is the code is repeating the first line of the sql query:

# Cria tabela
def tabela(self,li,sql):
    item = QTableWidgetItem
    col = 5 #será fixa
    self.dlg.tabela.setRowCount(li)
    self.dlg.tabela.setColumnCount(col)     
    self.dlg.tabela.setRowHeight(0,1) # Primeira linha

    for l in range(1,li):
        c=0    
        for resp in sql:                                                  
            self.dlg.tabela.setItem(l, c, item(resp))
            c+=1

Repeats the first line. How to solve?

2-  FP12| N1 |PMU Memorial JK| AO LADO DO MEMORIAL JK| ESC DA
3-  FP12| N1 |PMU Memorial JK| AO LADO DO MEMORIAL JK| ESC DA

1 answer

0


Maybe it’s because the variable c is stated within the for, at each iteration the initial value is zero, after the first iteration of the second for, add up 1, is a cycle that repeats itself with each iteration of the first for.

Declare c before, so it probably won’t repeat the lines.

c = 0
for l in range(1,li):   
        for resp in sql:                                                  
            self.dlg.tabela.setItem(l, c, item(resp))
            c += 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.