learncode
learncode

Reputation: 1113

Access particular element/item in QTableView?

How can we access the element in QtableView? The line self.tableView.item(1,1) does not sem to work? It gives error AttributeError: 'QTableView' object has no attribute 'item'

How can we access a particular element in QTableView say (3,4)?

Upvotes: 1

Views: 1210

Answers (1)

ekhumoro
ekhumoro

Reputation: 120578

I you're using a QStandardItemModel with the QTableView, you can do this:

model = self.tableView.model()
item = model.item(1, 1)

EDIT:

If you want the item's text, you can do:

text = item.text()

For the other properties of items, see the QStandardItem reference.

Upvotes: 1

Related Questions