How to get cell value from selected row (QTableView)?

I have it QTableView, and I need to get the value (string) from the first cell of the selected row (you can select any cell in the row). But I need this value only if exactly one row is selected.

I thought: I need to get the index of the selected row, and then get the value of the first set on this row, but I could not find a way to do this.

+5
source share
1 answer
myTableView->selectionModel()->currentIndex().row()

Gives you the index of the currently selected row. From there, you should have enough information to find a pair of rows / columns in your model.

It will also QItemSelectionModel::selectedRows()tell you how many rows are selected.

+11
source

All Articles