i have the following code (PyQt)
:
searchFrameObject.tableWidget.setRowCount(rowCounter)
searchFrameObject.tableWidget.setColumnCount(5)
for row in range(rowCounter):
for column in range(5):
for result in query:
item = QtGui.QTableWidgetItem(_fromUtf8(result.name))
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
searchFrameObject.tableWidget.setItem(row,column,item)
#item = QtGui.QTableWidgetItem(String(result.bought_price))
#item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
#searchFrameObject.tableWidget.setItem(row,column+1,item)
#item = QtGui.QTableWidgetItem(result.bought_date)
#item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
#searchFrameObject.tableWidget.setItem(row,column+2,item)
item = QtGui.QTableWidgetItem(result.stock)
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
searchFrameObject.tableWidget.setItem(row,column+3,item)
item = QtGui.QTableWidgetItem(result.minimum_bound)
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEnabled)
searchFrameObject.tableWidget.setItem(row,column+4,item)
When i search in DB, i print result.name
or print result.stock
, everything is OK. But when i import them into QtableWidget
i see just node result.name
addeed to widgets
. (all of nodes filled from result.name
)
My Question is , How i fill rows and columns with my fields?
Try commenting out the line
for column in range(5):
and setcolumn
to0
.There seems to be no point in running that loop because you are manually incrementing the column number in which you want
item
to be added.One more thing there is no point in running a loop over
query
because what appears in a particular row is what comes out last inquery
. Plus you are uselessly choking the memory by creating(len(query) - 1) * 5
items which could potentially be never used again. Better comment outfor result in query:
and replace it withresult = list(query)[-1]
.