0

i have a big problem , i need to display a data from sqlite3 db in a qtablewidget, but when i store a new information the table show

     column1 column2 column3 column4 ....
row1 empty     empty    empty   empty
row2 data      empty    empty   empty
row3 data      data     data    empty
row4 data      data     data    data 

my code is to show the items in the table def ActualizarBase(self): #Cargamos la base de datos y la colocamos en la tabla

 self.cursor.execute("SELECT * FROM Operaciones")
 filas = self.cursor.fetchall()
 self.numerodefilas=len(filas)
 self.ui.tableWidget.setRowCount(self.numerodefilas)
 #print filas[0]

 for j in range(self.numerodefilas):

     fila = filas[j]
 for i in range(1,len(filas)):
     elemento = fila[i]
     print 'elemento= '+ str(elemento)
     #print i
     elemento = str(elemento)
     if elemento == 'None' : elemento = ' '
     item=None
     item = QtGui.QTableWidgetItem()
     item.setText(QtGui.QApplication.translate("Hucha", str(elemento), None, QtGui.QApplication.UnicodeUTF8))
     self.ui.tableWidget.setItem(j,i-1,item)

any suggerence is welcome

  • It's difficult to understand the question, could you show the desired outcome? – Morgan Wilde Jul 16 '13 at 06:00
  • i need the all fields of the table filled with data but the table show the data of one cell then jump for the other row two cells the other rows three cells and so ... – user2585919 Jul 16 '13 at 06:26

1 Answers1

0

"but the table show the data of one cell then jump for the other row two cells the other rows three cells and so ... ", that is because you did not set self.ui.tableWidget.setColumnCount(numberOfColumns) . Also this is wrong: for i in range(1,len(filas)): , i shoud be in range(0, numberOfColumns) but first you must know max number of columns or find it if you do not know it: max(len(fila)) for fila in filas.

Aleksandar
  • 3,541
  • 4
  • 34
  • 57