[PyKDE] QTable Behaviour

Andreas Pauley andreasp+pykde at qbcon.com
Wed Mar 16 13:42:25 GMT 2005

Hi all,

I've got a QTable with a few columns that represent my point-of-sale 
transactions (Item Code, Description etc.), and I'm struggling a bit to 
figure out how to get my QTable to behave itself.

The first column (Item Code) is editable, and when a user types in an item 
code (and press enter) the following should happen:
- The rest of the columns should be updated with data from the system
- A new row should be inserted at the end of my table
- My cursor focus should be put on the Item Code of the new row, ready to 
repeat the whole process

I've managed to get this process to work the first time, but as soon as I 
press enter the second time, I get some weird behaviour.

Here's what I did so far:
I connected the valueChanged() signal of the table to a slot I called 
(Please feel free to suggest better naming conventions)

My processItem() looks like this:
     def processItem(self):
         print 'begin processItem'
         currentRow = self.tblItems.currentRow()
         numRows = self.tblItems.numRows()
         self.tblItems.setText(currentRow, 1,  str(numRows)+' '+time.ctime(time.time()))
         self.tblItems.editCell(currentRow+1, 0)
         print 'end processItem'

Any advice?

To see this code in action you can do a subversion checkout:
svn co svn://svn.qbcon.com/repos/python/qualitypos/trunk qualitypos

Then just run main.py, log in as the default user and press F2 to start a 
cashier session.

I can also make a tarball/zipfile available for download, if that will 
make it easier for anyone.


More information about the PyQt mailing list