I want to refresh content of QTableView when model data changed.
But I can't find a way of specificing the value of QModelIndex instance.
See questions in below code.
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import QModelIndex, Qt
class MyTableModel(QtCore.QAbstractTableModel):
def __init__(self, data=[[]], parent=None):
super().__init__(parent)
self.data = data
...
data = [
[1, 2],
[3, 4],
]
model = MyTableModel(data)
view = QtWidgets.QTableView()
view.setModel(model)
# changing a data element at row 1, column 0
data[1][0] = 30
row_index = QModelIndex()
# Question: how do I set row_index as 1?
col_index = QModelIndex()
# Question: how do I set col_index as 0?
model.dataChanged.emit(row_index, col_index, Qt.DisplayRole)
The
indexmethod of model is for that.