Python 从QTableView中提取最后一列数据

Python 从QTableView中提取最后一列数据,python,pyqt,Python,Pyqt,从的答案中,我找到了访问QTableView中所选行的第一列的方法。但是如何访问最后一列,而不硬编码列号 itmIndex = self.viewInQuestion.currentIndex() id = itmIndex.sibling(itmIndex.row(), -1) 不起作用。有什么建议吗?以下方法有效: itmIndex = self.viewInQuestion.currentIndex() id = itmIn

从的答案中,我找到了访问QTableView中所选行的第一列的方法。但是如何访问最后一列,而不硬编码列号

        itmIndex = self.viewInQuestion.currentIndex()
        id = itmIndex.sibling(itmIndex.row(), -1)

不起作用。有什么建议吗?

以下方法有效:

        itmIndex = self.viewInQuestion.currentIndex()
        id = itmIndex.sibling(itmIndex.row(), self.modelForView.columnCount() - 1)
        itmCt = self.modelForView.data(id).toFloat()