views:

37

answers:

1

I'm working on a small project in QT (well, pyQT4 actually, but it shouldn't matter too much) and I've run into the following problem. I have a QTableView with several rows and columns. I have set the selection mode to be rows only. When I call getSelectedIndexes() on my QTableView, I get an index for every row and column, which in the current setup means that I get an extra 5 Indexes for each selected row, which is less than ideal, since I only need to know the row, not the column. Is there any way to get just one Index per row other than filtering the list that I get from getSelectedIndexes()?

+4  A: 

The selection is maintained by QItemSelectionModel, which provides a method called selectedRows() that does what you want. For example:

myTableView->selectionModel()->selectedRows()
Lukáš Lalinský