Dynamic table in python

1

I have a problem and I can not identify the error.

I am creating a Python PivotTable where it will be populated 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
    
asked by anonymous 22.10.2016 / 00:57

1 answer

0

Maybe it's because the c variable is declared inside for , at each iteration the initial value is zero , after the first iteration of the second for , sum 1 , is a cycle that repeats itself at each iteration of the first for .

Declare c before, so probably will not repeat lines.

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