QTableWidget updating columns in a single row
Vincent Vande Vyvre
vincent.vandevyvre at swing.be
Wed Apr 24 14:51:04 EDT 2013
Le 24/04/2013 19:12, Sara Lochtie a écrit :
> On Tuesday, April 23, 2013 11:22:29 PM UTC-7, Sara Lochtie wrote:
>> I have written a GUI that gets data sent to it in real time and this data is displayed in a table. Every time data is sent in it is displayed in the table in a new row. My problem is that I would like to have the data just replace the old in the first row.
>>
>>
>>
>> The table has 6 columns (A, B, C, D, E, F) I want the new data to continue replacing the old data in the same row unless the data that goes under column A changes, at which point a new row would be added.
>>
>>
>>
>> Does anyone have tips on how to approach this? I can post a portion of my code to get a better idea of what I have done.
> So that is where I am stuck. I don't how to compare them and I am trying to avoiding saving the data to a file.
>
> This is the code that I have:
>
>
>
>
>
> if msg.arg2() != ERROR:
> entry = (A, B, C, D, E, F)
> self.data.append(entry)
>
> data = self.data
>
> # Display how many runs occurred
> self.statusBar().showMessage('Data read. %s Run(s) Occurred.' % self.runCount)
>
> # Populates table by adding only new entries to the end of the table
> lastRow = self.table.rowCount()
> self.table.setRowCount(len(data))
> for entryPos in range(lastRow, len(data)):
> for fieldPos in range(6):
> item = QtGui.QTableWidgetItem(str(data[entryPos][fieldPos]))
> self.table.setItem(entryPos, fieldPos, item)
> self.table.resizeColumnsToContents()
> self.table.horizontalHeader().setStretchLastSection(True)
> self.currentRunLabel.setText('Current Run: ' + str(self.runCount))
> self.currentLineLabel.setText('Number of lines: ' + str(len(self.data)))
> print('End of %s. run: %s. entries found' % (self.runCount, len(self.data)))
As sayed by Chris "Kwpolska", you can compare the new data with the data
of the first row.
Something like that:
# Get the content of row 0, column A
first = str(self.table.item(0, 0).text())
for entryPos in range(lastRow, len(data)):
if str(data[entryPos][0]) == first:
self.update_first_row(data[entryPos])
else:
self.add_new_row(data[entryPos])
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
More information about the Python-list
mailing list