PyQt - 更新模型时自动刷新自定义视图? [英] PyQt - Automatically refresh a custom view when the model is updated?

查看:54
本文介绍了PyQt - 更新模型时自动刷新自定义视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

By default, the built-in views in PyQt can auto-refresh itself when its model has been updated. I wrote my own chart view, but I don't know how to do it, I have to manually update it for many times.

我应该使用哪个信号?

推荐答案

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

You need to connect your view to the dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) signal of the model:

只要现有项目中的数据发生变化,就会发出此信号.

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

如果项目属于同一个父项,则受影响的是那些包括 topLeft 和 bottomRight 之间.如果物品没有同一个父级,行为未定义.

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.

重新实现setData()函数时,这个信号必须是显式发出.

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

这篇关于PyQt - 更新模型时自动刷新自定义视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆