Python - Add checkbox to every row in QTableWidget
<p>I am trying to add a checkbow to every row in a QTableWidget, unfortunately it only seems to appear in the first row. Here is my code:</p>

<pre><code>data = ['first_row', 'second_row', 'third_row']
nb_row = len(data)
nb_col = 2

qTable = self.dockwidget.tableWidget
qTable.setRowCount(nb_row)
qTable.setColumnCount(nb_col)
chkBoxItem = QTableWidgetItem()

for row in range(nb_row):
    for col in [0]:
        item = QTableWidgetItem(str(data[row]))
        qTable.setItem(row,col,item)
    for col in [1]:
        chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
        chkBoxItem.setCheckState(QtCore.Qt.Unchecked)       
        qTable.setItem(row,col,chkBoxItem)
</code></pre>

<p>Am I missing something obvious?</p>

<p>I checked the following posts also:</p>

<ul>
<li><a href="http://stackoverflow.com/questions/12366521/pyqt-checkbox-in-qtablewidget">PyQt : Checkbox in QTableWidget</a></li>
<li><a href="http://stackoverflow.com/questions/32458111/pyqt-allign-checkbox-and-put-it-in-every-row">PyQt allign checkbox and put it in every row</a></li>
</ul>

<p>Ok, I just had to put <code>chkBoxItem = QTableWidgetItem()</code> inside the last loop (<em>I guess it has to create a new <code>QTableWidgetItem()</code> item for each row</em>...):</p>

<pre><code>for col in [1]:
    chkBoxItem = QTableWidgetItem()
    chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
    chkBoxItem.setCheckState(QtCore.Qt.Unchecked)       
    qTable.setItem(row,col,chkBoxItem)
</code></pre>

python pyqt qtablewidget qcheckbox