So I've been working on a quiz software with PyQt5. Before displaying the results, I designed it to show a table of the questions that have been answered and the answers selected for them (MCQs only) so that if the user wanted to correct an answer they could do that before submitting. I could think of two ways to do this. One was to get the row number of the cell clicked and then use that to index through the list(self.history) I used to input questions.
for x in self.history:
number = self.history.index(x)
item = QtWidgets.QTableWidgetItem()
item.setText(f"Question no. {number + 1}")
item = self.answers_table.verticalHeaderItem(number)
question = qtw.QTableWidgetItem()
self.answers_table.setItem(number, 0, question)
question.setText(x.question)
question.setFlags(QtCore.Qt.ItemIsEnabled)
answer_select = qtw.QTableWidgetItem()
self.answers_table.setItem(number, 1, answer_select)
answer_select.setText(x.answer_select)
answer_select.setFlags(QtCore.Qt.ItemIsEnabled)
So if I could get the row number, I could then use it as an index to that object in the list and that would work. But I can't seem to find a way to get that.
The other way I thought I could do this was if I could keep that index as an invisible value like I can in QComboBox in the currentData()
variable but I can't seem to find a way to do that either without making it a visible column.