I have problem getting selected rows from QTableWidget. I have table like this:
[id] [ key ]
0 test
1 pass
I want to get every row’s key values. I tried QTableWidget->selectedIndexes(); but it says it’s protected and I can’t access that. When I tried QTableWidget->SelectionModel->selectedIndexes, I don’t know how to loop through list and get the key values. Do anyone know better way how can I do it?
Regards.
I’m assuming that you set the selection behavior of your table widget to select rows.
You can always access the so-called “selection model” of any item view/widget.
QTableWidgetinherits fromQAbstractItemView, which gives you access to this special model. This model can tell you the selected rows as a list ofQModelIndex, which can then tell you the row. Once you’ve got them, you can access the table content, in your case the text in the column with index 1 (key column).