强制更新 QTableView + PyQt 中的 QSqlTableModel

发布于 2024-09-29 06:14:06 字数 159 浏览 1 评论 0原文

我有一个 QTableView,它显示来自 QSqlTableModel 的数据。我希望我的模型在用户点击“刷新”按钮时检查更改,但我找不到更新数据的方法。 我在模型上尝试了 Reset() 和 update() 方法,但没有任何结果。

是否可以从数据库“重新读取”​​并更新模型?如何?

I have a QTableView which displays data from a QSqlTableModel. I want my model to check for changes when a user hits a "refresh" button but I can't find a way to update the data.
I tried the reset() and update() methods on the model without any result.

Is it possible to "re-read" from the database and update the model? How?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨后咖啡店 2024-10-06 06:14:06

由于您没有说明模型中的更改内容,因此我将假设最简单的更改形式(更改的数据)。

对我来说 model.select() 可以更新模型中的数据并强制视图自行更新。

As you dont state what you canged in your model, ill assume the simplest form of change (changed data).

For me model.select() works to update the data in the model and force the View to update itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文