Get content of cell from QTableView
-
Hi,
You use the index method of the model you set on your view.
-
@SGaist said in Get content of cell from QTableView:
Hi,
You use the index method of the model you set on your view.
But I would like to get value of cell, not index
-
-
Short version:
ui->tableView->model()->index(index.row(),0).data().toInt();
-
@imene
You are in the middle ofMainWindow
constructor. On the line you show, in theindex.row()
expression what is theindex
variable, where is it declared, what is its type?The point of this question is to get the content of a
QTableView
cell, where the cell you want is in the model atQModelIndex index
. -
Hi, I've tried the same (almost, because in python), but I gain error: name 'index' is not defined
-
@Karoluss96 Please post the code.
Did you define the "index" member variable? -
No, but It is noe build-in function? like here: https://stackoverflow.com/questions/37035756/how-to-select-multiple-rows-in-qtableview-using-selectionmodel
-
@Karoluss96 If you read this thread, especially what @JonB asked you will see that it is unclear what index is in the code posted. Sinse it is not my code I also don't know.
-
I put tableView.currentIndex() here, that take the number of index for data, which work correct, but later .data() says: ' 'int' object has no attribute 'data''
-
@Karoluss96 Can you please post the code?
-
@Karoluss96 said in Get content of cell from QTableView:
but later .data() says: ' 'int' object has no attribute 'data''
Do you expect people to say anything useful about this when you show no code?
-
My plan is to get data from whole table and separate it between rows to make sql question (Insert Into those who are new added)
now (after cutting of .toInt() ) looks that:data= self.dlg.tableView_3.model().index(self.dlg.tableView_3.currentIndex().row(),0) dt=data.data() print (dt)
-
It take only the first record from selected row, wheras I need all data from selected row, which later I want to put (separatly one-by-one) to a sql question
-
@Karoluss96 said in Get content of cell from QTableView:
It take only the first record from selected row
Careful with words, you mean column not record. So look at your
0
argument which only fetches the data for column 0, and write code to pick up all the columns in the row if that is what you want....