How do you retrieve the cell row of a changed QComboBox as a QCellWidget of a QTableWidget?
<p>I am trying to get the row and column of a changed combobox in a QTableWidget.
Here is how my table is set up. Look at the bottom to see what I am trying to do.</p>

<pre><code>def click_btn_mailouts(self):

    self.cur.execute("""SELECT s.StudentID, s.FullName, m.PreviouslyMailed, m.nextMail, m.learnersDate, m.RestrictedDate, m.DefensiveDate FROM
                        StudentProfile s LEFT JOIN Mailouts m ON s.studentID=m.studentID""")
    self.all_data = self.cur.fetchall()

    self.table.setRowCount(len(self.all_data))
    self.tableFields = ["Check","Full name","Previously mailed?","Next mail","learners date","Restricted date","Defensive driving date"]
    self.columnList = ["StudentID","FullName","PreviouslyMailed","NextMail","learnersDate","RestrictedDate","DefensiveDate"]
    self.table.setColumnCount(len(self.tableFields))
    self.table.setHorizontalHeaderLabels(self.tableFields)
    self.checkbox_list = []
    for i, item in enumerate(self.all_data):
        FullName = QtGui.QTableWidgetItem(str(item[1]))
        PreviouslyMailed = QtGui.QComboBox()
        PreviouslyMailed.addItem("Yes")
        PreviouslyMailed.addItem("No")
        LearnersDate = QtGui.QTableWidgetItem(str(item[3]))
        RestrictedDate = QtGui.QTableWidgetItem(str(item[4]))
        DefensiveDate = QtGui.QTableWidgetItem(str(item[5]))
        NextMail = QtGui.QTableWidgetItem(str(item[6]))
        self.table.setItem(i, 1, FullName)
        self.table.setCellWidget(i, 2, PreviouslyMailed)
        self.table.setItem(i, 3, LearnersDate)
        self.table.setItem(i, 4, RestrictedDate)
        self.table.setItem(i, 5, DefensiveDate)
        self.table.setItem(i, 6, NextMail)
        chkBoxItem = QtGui.QTableWidgetItem()
        chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
        chkBoxItem.setCheckState(QtCore.Qt.Unchecked)
        self.checkbox_list.append(chkBoxItem)
        self.table.setItem(i, 0, self.checkbox_list[i])
        FullName.setFlags(FullName.flags() &amp; ~Qt.ItemIsEditable)
        NextMail.setFlags(NextMail.flags() &amp; ~Qt.ItemIsEditable)

        """Heres what I am trying to do:"""        
        PreviouslyMailed.currentIndexChanged.connect(self.comboBox_change(self.table.cellWidget(row,1).currentText()))
        """I want 'row' to be the row that has the combobox that has been changed."""
</code></pre>

<p>If I understand correctly, when attaching the signal <code>i</code> will be the value of the row that you want to send (or, maybe <code>i+1</code>?). You can easily send additional data with Qt signals, by using a wrapper function or <code>lambda</code> as follows:</p>

<pre><code>for a in range(5):
    x = QComboBox()
    x.currentIndexChanged.connect( lambda i: my_other_function(i, another_var) )
</code></pre>

<p>Here, we connect the <code>lambda</code> to the signal, and when it is called the internal function will in turn be called with the extra data. This is functionally equivalent to:</p>

<pre><code>def my_wrapper(i):
    my_other_function(i, another_var)

for a in range(5):
    x = QComboBox()
    x.currentIndexChanged.connect( my_wrapper )
</code></pre>

<p>But, as you will discover if you try to do this, this doesn't always work. If you try and pass the variable <code>a</code> to the internal function, it will <em>always</em> be set to the value <code>a</code> was at the end of the loop. </p>

<pre><code>for a in range(5):
    x = QComboBox()
    x.currentIndexChanged.connect( lambda i: my_other_function(i, a) ) # a will always be 4
</code></pre>

<p>You can get around this by rebinding the value of <code>a</code> to a new variable each time â the easiest way being passing it in as a named parameter to the <code>lambda</code>. For example â</p>

<pre><code>for a in range(5):
    x = QComboBox()
    x.currentIndexChanged.connect( lambda i, a=a: my_other_function(i, a) ) # Each combo will send the index, plus the value of a
</code></pre>

<p>You should be able to use the above to send the correct value for <code>row</code> for each <code>QComboBox</code> you create. </p>

python pyqt