Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44283

Re: QTableWidget updating columns in a single row

Date 2013-04-24 20:51 +0200
From Vincent Vande Vyvre <vincent.vandevyvre@swing.be>
Subject Re: QTableWidget updating columns in a single row
References <1a87f00d-636d-4795-80d5-7bf196d1177f@googlegroups.com> <5c8ead62-ebc8-429c-a531-9592a958983d@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1030.1366829923.3114.python-list@python.org> (permalink)

Show all headers | View raw


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>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

QTableWidget updating columns in a single row Sara Lochtie <sara.lochtie@gmail.com> - 2013-04-23 23:22 -0700
  Re: QTableWidget updating columns in a single row Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-04-24 09:58 +0200
  Re: QTableWidget updating columns in a single row Sara Lochtie <sara.lochtie@gmail.com> - 2013-04-24 10:12 -0700
    Re: QTableWidget updating columns in a single row Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-04-24 19:57 +0200
    Re: QTableWidget updating columns in a single row Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-04-24 20:51 +0200
      Re: QTableWidget updating columns in a single row Sara Lochtie <sara.lochtie@gmail.com> - 2013-04-26 12:14 -0700

csiph-web