PDA

View Full Version : pyqt4 reading values from rows of QTableWidget



stephen76
2nd August 2010, 14:15
Hi,
I am new to pyqt and have been looking for examples of how to iterate through a QTableWidget to get the values. I can't seem to find anything online(probaly looking for the wrong keywords). Each row of my table consists of a default text field in the first column and comboBoxes in the second and third columns. I need to iterate through each row get the string from the first column and the option picked in each combobox. Any simple examples would be much appreciated
Thanks in advance
Stephen

stephen76
2nd August 2010, 16:41
ok ... after a few hours I think I have figured it out...
the function that reads the table is like so ..


def addNewPasses(self):
allRows = self.ui.tableWidget.rowCount()
for row in xrange(0,allRows):
twi0 = self.ui.tableWidget.item(row,0)
twi1 = self.ui.tableWidget.cellWidget(row,1)
twi2 = self.ui.tableWidget.cellWidget(row,2)
print twi0.text()+' '+twi1.currentText()+' '+twi2.currentText()


if there is a better more streamlined way let me know!
stephen

ad3d
10th January 2011, 09:55
I am using QDateEdit & QComboBox in QTableWidget in few columns but if i try to use the above method its working fine for QComboBox but its not working for QDateEdit

i have set QDateEdit in 1st column of the table & i am trying to access that using below line

date_applfrm = self.leaves_app_table.cellWidget(i,0)
self.date_applfrm.date()

its saying unknown attribute date_applfrm (error is for the 2nd line)

can some one plz help me on this...
thanx in advance