How do I get the entire selected row in a Qt proxy model?
<p>The code below is a working QTableView, which is using a QAbstractTableModel, which is using a QSortFilterProxyModel. I've managed to figure out how to get data out of a <em>single</em> <em>cell</em> of a selected row, but not the entire row at once (e.g. as a list of strings). Please can I have some suggestions of what to try?</p>

<p>(I'm using Python, but if someone knows how to do it in another language I'll <em>try</em> to translate it...)</p>

<pre><code>from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys


class CustomTableModel(QAbstractTableModel):
    def __init__(self, cells=[[]], headers=[]):
        super(CustomTableModel, self).__init__()
        self._cells = cells
        self._headers = headers

    def data(self, index, role):
        if index.isValid() and (role == Qt.DisplayRole):
            return self._cells[index.row()][index.column()]

    def rowCount(self, parent=None):
        return len(self._cells)

    def columnCount(self, parent=None):
        return len(self._headers)

    def flags(self, index):
        return Qt.ItemIsEnabled | Qt.ItemIsSelectable


class CustomSortFilterProxyModel(QSortFilterProxyModel):
    def __init__(self):
        super(CustomSortFilterProxyModel, self).__init__()

    def get_selected_row(self):
        # Unsure what to put here??
        pass


def table_clicked():
    selected_indexes = table_view.selectionModel().selectedRows()
    first_cell_selected = proxy_model.data(proxy_model.index(selected_indexes[0].row(), 0), Qt.DisplayRole).toString()
    print(first_cell_selected)

    # But rather than the above I would like to be able to do something like:
    print(proxy_model.get_selected_row())
    # and for it to print out everything in the row e.g. ['Cell 1', 'Cell 2', 'Cell 3']


app = QApplication(sys.argv)

table_data = [["Cell 1", "Cell 2", "Cell 3"], ["Cell 4", "Cell 5", "Cell 6"]]
table_headers = ["Header 1", "Header 2", "Header 3"]

model = CustomTableModel(table_data, table_headers)

proxy_model = CustomSortFilterProxyModel()
proxy_model.setDynamicSortFilter(True)
proxy_model.setSourceModel(model)

table_view = QTableView()
table_view.setModel(proxy_model)
table_view.setSelectionBehavior(QAbstractItemView.SelectRows)
table_view.setSelectionMode(QAbstractItemView.SingleSelection)
table_view.setSortingEnabled(True)
table_view.clicked.connect(table_clicked)
table_view.show()

sys.exit(app.exec_())
</code></pre>

<p>It might be related to <a href="https://stackoverflow.com/questions/28160584/how-to-get-index-row-number-from-source-model">How to get Index Row number from Source Model</a></p>