Skip to main content
 首页 » 编程设计

python之PyQt之更新模型时自动刷新自定义 View

2025年05月04日8qq号

默认情况下,PyQt 中的内置 View 可以在其模型更新时自动刷新。我自己写了图 TableView ,但是我不知道怎么做,我不得不手动更新很多次。

我应该使用哪个信号?

请您参考如下方法:

您需要将 View 连接到模型的 dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) 信号:

This signal is emitted whenever the data in an existing item changes.

If the items are of the same parent, the affected ones are those between topLeft and bottomRight inclusive. If the items do not have the same parent, the behavior is undefined.

When reimplementing the setData() function, this signal must be emitted explicitly.