[PyKDE] QTable Behaviour

Andreas Pauley andreasp+pykde at qbcon.com
Wed Mar 16 15:14:27 GMT 2005

Just for clarification, the "weird behaviour" is that it seems as if the 
QTable loses cursor focus, and I cant edit a cell unless I double-click on 

I just saw a setCurrentCell() method, I'll try that instead of editCell()

If I want to reference a column, where do I start counting?
The column numbers doesn't seem to start at 0 or 1.

On Wed, 16 Mar 2005, Andreas Pauley wrote:

> 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 
> processItem().
> (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.insertRows(currentRow+1)
> 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.
> Regards,
> Andreas

More information about the PyQt mailing list