简体   繁体   English

Python PyQt4每1分钟更新一次小部件上的数据

[英]Python PyQt4 update data on widget every 1 min

I have a PyQT4 application that reads information from a local sqlite3 database and display the data using QTableWidget . 我有一个PyQT4应用程序,它从本地sqlite3数据库读取信息并使用QTableWidget显示数据。

The data stored on the sqlite3 changes from time to time.So, I want to update my Table Widget once every 1 min. 存储在sqlite3上的数据会不时更改。所以,我想每1分钟更新一次Table Widget。

To simplify matters, let's assume i already have a function called ' Refresh() ' that will refresh the contents in my Table Widget. 为了简化问题,我们假设我已经有一个名为' Refresh() '的函数,它将刷新Table Widget中的内容。

How do i make this function ' Refresh()' to execute every 1 min? 如何使此功能' 刷新()'每1分钟执行一次? I have done this in Tkinter using time.after() . 我在Tkinter使用time.after()完成了这个。 I have no idea how to do it in PyQt . 我不知道如何在PyQt做到这一点。

Your function should probably be called paintEvent . 你的函数应该叫做paintEvent Then make a QTimer like so: 然后像这样制作一个QTimer

self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.update)
self.timer.start(60000) #trigger every minute.

That is unless you need to for some reason update something in the backed and not in the front end (in other words the function is not used for drawing. Otherwise it should allmost without question be called paintEvent ). 除非你因为某些原因需要更新某些内容而不是前端(换句话说,该函数用于绘图。否则它应该最重要的是被称为paintEvent )。 Then do: 然后做:

self.timer.timeout.connect(self.Refresh)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM