0

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?

PersianGulf
  • 2,845
  • 6
  • 47
  • 67

1 Answers1

1

Try commenting out the line for column in range(5): and set column to 0.

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 in query. Plus you are uselessly choking the memory by creating (len(query) - 1) * 5 items which could potentially be never used again. Better comment out for result in query: and replace it with result = list(query)[-1].

Bleeding Fingers
  • 6,993
  • 7
  • 46
  • 74
  • I solved , it were very important : 1. column for 2. because i defined my locale persian Iran, it couldn't get integer, So i defined a function for convert integer to persian. – PersianGulf Sep 09 '13 at 08:22
  • @MohsenPahlevanzadeh not sure I quite get what you are pointing out to – Bleeding Fingers Sep 10 '13 at 04:17