【发布时间】:2014-07-10 06:45:42
【问题描述】:
在我的应用程序中,我使用 API 调用获取记录,然后将数据动态添加到 QTableWidget。到目前为止,这是我的代码的 sn-p:
class TriageUI(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_TriageWindow()
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.move(QtGui.QApplication.desktop().screen().rect().center()- self.rect().center())
self.ui.setupUi(self)
self.update_records()
def update_records(self):
#items are the results from the API fetch
items = json.loads(get_triage_queue(COOKIES, SERVER, PORT))
rows = len(items['objects'])
self.ui.tableWidget.setColumnCount(5)
self.ui.tableWidget.setRowCount(rows)
index = 0
column = 0
for j in items['objects']:
for key, value in j.iteritems():
f = QtGui.QTableWidgetItem(str(value))
self.ui.tableWidget.setItem(index, column, QtGui.QTableWidgetItem(f))
column = column + 1
但是,我希望能够定期(例如 15 秒后)对数据进行 API 调用,然后将结果中的任何新数据项添加到表中。我怎样才能做到这一点。
提前谢谢你。
【问题讨论】:
-
你应该看看QTimer
标签: python pyqt pyqt4 qtablewidget