Important: Please read the Qt Code of Conduct -

PyQt5 How to get data from current row of QTableView

  • if i write :

     name = self.tableView.model().data(index)

    it back me a string of the current cell so i want the specific cell which is column 1

        def contextMenu(self,pos):
            index = self.tableView.currentIndex()
            row = index.row
            name = self.tableView.model().data(self.tableView.model().index(row, 1)) #when it comes to this line program execution stop without sending error

  • Banned

    To help you trouble shoot this I would suggest you do the following so that you are sure of what your are getting:

    NewIndex = self.tableView.model().index(row, 1)
    print('Index is :',NewIndex)
    Name = self.tableView.model().data(NewIndex)

    Then you can see what your NewIndex is and/or see if it is working correctly as I would be pretty confident that giving the latter function a valid Index gets the value I would be expecting in the Name variable since it does this fine already. Thus this means perhaps what that internal piece is returning is not what you are expecting.

  • @denni-0

            index = self.tableView.currentIndex()
            NewIndex = self.tableView.model().index(index.row(), 0)

    I must write index.row() with parenthesis.
    Now it works.Thanks

Log in to reply