PDA

View Full Version : Working out table's current row from pushbutton click



shooogun
16th March 2008, 23:17
Hi,

I've got a table, and when I create a new row I create a new pushbutton to go into the last column of the new row. I'm trying to workout how to get the currentRow when clicking the pushbutton without selecting the row.

I've got this pseudo code


def printThis(self):
currentRow = self.table.currentRow()
print currentRow

def addRow(self):
newButton = QPushButton(Qstring('push'))
self.connect(newButton,SIGNAL("clicked()"),self.printThis)

newRow = self.table.rowCount()
self.table.insertRow(newRow)
#set table widget items
self.table.setCellWidget(newRow, 3, newButton)


Help please?

wysota
16th March 2008, 23:40
You can use QSignalMapper and map between buttons and row numbers. Or you can use dynamic properties to set some hidden data or you can just have an equivalent of QHash<QPushButton*, int> where you will store row numbers.