0

I have a QTableWidget with x rows and 2 columns. Sorting is enabled. I want to add a new Item:

def addlabel(self):
  rows = self.cui.tableWidget.rowCount()
  self.cui.tableWidget.insertRow(rows)
  self.cui.tableWidget.setItem(rows-1,0,QtGui.QTableWidgetItem("*New*"))

How can I track my new item without findItems(text, flags)? Is that possible?
Similar question: After editing the new item, it may changes the position because of the sorting. How can I track my edited Item? (I want the new positions(rows))

Hubschr
  • 1,285
  • 6
  • 18
  • 35

1 Answers1

1

Return the item from the method and later you can do item.row() to get the row.

def addlabel(self):
  rows = self.cui.tableWidget.rowCount()
  self.cui.tableWidget.insertRow(rows)
  item = QtGui.QTableWidgetItem("*New*")
  self.cui.tableWidget.setItem(rows-1,0,item)
  return item

# ...

# somewhere...
  label = self.addlabel()
  print label.row()
Avaris
  • 35,883
  • 7
  • 81
  • 72