我想刷新QTableView
模型数据更改时的内容。
但我找不到指定QModelIndex
实例值的方法。
请参阅以下代码中的问题。
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)