我有以下代码,我的查询工作正常:
###initilize Objects
self.dbObj = DbAbsLayer()
self.tableObj = MaterialsTable(dict())
####making queries, one for count row, another for result row
query = self.dbObj.session.query(MaterialsTable)
rowCounter = self.dbObj.session.query(MaterialsTable)
for attr , val in tmpDict.items():
query = query.filter(getattr(MaterialsTable,attr).like("%%%s%%" % val)).all()
rowCounter = rowCounter.filter(getattr(MaterialsTable,attr).like("%%%s%%" % val)).count()
##### commit my queries
self.dbObj.session.commit()
####setting up my QtableWidget
searchFrameObject.tableWidget.setRowCount(rowCounter)
searchFrameObject.tableWidget.setColumnCount(5)
######inserting into QtableWidget
for row in range(rowCounter):
for result in query:
item = QtGui.QTableWidgetItem(_fromUtf8(result.name))
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
searchFrameObject.tableWidget.setItem(row,0,item)
item = QtGui.QTableWidgetItem(_fromUtf8(integerToPersian(result.bought_price)))
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
searchFrameObject.tableWidget.setItem(row,1,item)
item = QtGui.QTableWidgetItem("date")#result.bought_date)
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
searchFrameObject.tableWidget.setItem(row,2,item)
item = QtGui.QTableWidgetItem(_fromUtf8(integerToPersian(result.stock)))
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
searchFrameObject.tableWidget.setItem(row,3,item)
print result.stock
print integerToPersian(result.stock)
item = QtGui.QTableWidgetItem(_fromUtf8(integerToPersian(result.minimum_bound)))
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
searchFrameObject.tableWidget.setItem(row,4,item)
print result.minimum_bound
在我的循环中print result.stock
,result.minimum.bound
我可以看到我在 DB 中可以看到的所有内容PHPMyAdmin
,但是当我添加到时QTableWidget
,我看到添加的最后一个结果。
我的问题是,我怎样才能将每个结果添加到QTableWidget
?