[PyQt] multiple row deletion in QTableWidget
He Jibo
hejibo at gmail.com
Tue Jul 13 17:54:07 BST 2010
Hi,
I am programming for a multiple row deletion in QTableWidget. I used a
sqlite database as the backend of QTableWidget. Below is my code.
I first find the row ID to be deleted, then delete all the IDs in the sqlite
database, then update the remaining data to show in the QTableWidget.
The first call of DelReocrdFunction is pretty good. I can delete several
rows and show in the table. But the second call of DelReocrdFunction does
not work. The database deletion code runs,
but does not actually the database ( cur.execute('DELETE FROM
csvtable WHERE __ID__=?',(ID[0].strip()))).
Could someone tell me what's run with it? Thanks.
def DelRecordFunction(self):
'''delete an existing record'''
## SelectedData = self.getSelectedData()
selRanges=self.table.selectedRanges()
ID2Delete=[]
for i in range(len(selRanges)):
selRange = selRanges[i]#just take the first range
topRow = selRange.topRow()
bottomRow = selRange.bottomRow()
rightColumn = selRange.rightColumn()
leftColumn = selRange.leftColumn()
print i,topRow,bottomRow
for row in range(topRow,bottomRow+1):
ID=str(self.table.item(row,0).text())
ID2Delete.append(ID)
print ID2Delete
cxn = sqlite3.connect(self.ProjectName+'.db')
cur = cxn.cursor()
for ID in ID2Delete:
cur.execute('DELETE FROM csvtable WHERE
__ID__=?',(ID[0].strip()))
print 'hi',ID
cxn.commit()
#update the data
data=[]
cur.execute('select * from csvtable')
for item in cur.fetchall():
data.append(list(item))
self.mydata=data
cxn.close()
print 'data len:',len(self.mydata)
self.table.refreshTable(self.header,self.mydata)
print 'delete success'
---------------------------
He Jibo
Department of Psychology,
Beckman Institute for Advanced Science and Technology
University of Illinois, Urbana Champaign,
603 East Daniel St.,
Champaign, IL 61820
website: www.hejibo.info
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100713/d958773c/attachment.html>
More information about the PyQt
mailing list