Frage

self.table.setRowCount(5)
self.table.setColumnCount(8)
self.table.setHorizontalHeaderLabels(title)
            for i,row in enumerate(cur):
                for j,val in enumerate(row):
                    self.table.setItem(i, j, QtGui.QTableWidgetItem(str(val)))

I have made a table, which I want to contain multiple rows of data, how could I have rowcount +1 for every line of data inserted into the table? Instead of me having to have a limit of rows for data to be inserted into. If anymore information is required please let me know.

War es hilfreich?

Lösung

As far as I know rowCount will give you exactly the number of rows you have in the table. So, I think your problem is how to insert new rows. That seems to be quite simple if you use insertRow I cannot check the code now because I have no python interpreter, but something like these lines should work:

self.table.setColumnCount(8)
self.table.setHorizontalHeaderLabels(title)
for i,row in enumerate(cur):
    self.table.insertRows(self.table.rowCount())
    for j,val in enumerate(row):
        self.table.setItem(i, j, QtGui.QTableWidgetItem(str(val)))
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top