Unsolved 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
-
index = self.tableView.currentIndex() NewIndex = self.tableView.model().index(index.row(), 0)
I must write index.row() with parenthesis.
Now it works.Thanks -
for tableWidget
index = self.tableWidget_2.currentIndex() NewIndex = self.tableWidget_2.model().index(index.row(), 0) print('Index is :',NewIndex) Name = self.tableWidget_2.model().data(NewIndex) print(Name)
-
@phoenix_mashhad
To save from keep repeatingself.tableWidget_2.model()
, one can shortcut getting at a column in the same row viaNewIndex = self.tableWidget_2.currentIndex().siblingAtColumn(0)
One can shortcut getting the data for an index via
Name = NexIndex.data()
-
THANK YOU SO MUCH @denni-0. I dont could FIND THIS anywere!!!, I lost 3 days serching