Answer the question
In order to leave comments, you need to log in
How to access a checkbox in a table?
I'm making an application, as planned, a table is generated from the data received via REST. I make a checkbox the first cell of each row. I hang on each checkbox the function of recalculating the total amount of one of the columns. By design, the function should go through all the rows and summarize only the cells of those rows where the checkbox is checked.
The question is how do I get the state of the checkbox when iterating over the rows?
This is how I generate the table content:
table = self.ui.historyTable
for i, op in enumerate(totalop):
self.checkbox = QtWidgets.QCheckBox()
self.checkbox.setCheckState(QtCore.Qt.CheckState.Checked)
self.checkbox.setStyleSheet('margin-left:12px;')
self.checkbox.stateChanged.connect(self.recalc)
table.setCellWidget(i, 0, self.checkbox)
table.setItem(i, 1, QtWidgets.QTableWidgetItem(ticker)
table.setItem(i, 2, QtWidgets.QTableWidgetItem(op.get('operationType')))
table.setItem(i, 3, QtWidgets.QTableWidgetItem(str(op.get('price')).replace('.', ',')))
def recalc(self):
table = self.ui.historyTable
for i in range(table.rowCount()):
item = table.item(i, 0)
# ???
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question