0

当我的代码中包含在 QStringListModel 中的数据发生更改时,beginResetModel() 和 endResetModel() 不起作用,任何人都可以解释为什么?

import sys

from PyQt4.QtGui import *
from PyQt4.QtCore import *



class BoxLayout(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.view = QTableView()
        hbox = QHBoxLayout()
        hbox.addWidget(self.view)
        self.setLayout(hbox)
        self.resize(800, 600)

        self.lst=[]
        self.stringListModel=QStringListModel (self.lst)
        self.view.setModel(self.stringListModel)

        self.timer = QTimer(self);
        self.timer.timeout.connect(self.timerHit)
        self.timer.start(1000)

    def timerHit(self):
        self.stringListModel.beginResetModel ()
        self.lst.append(QTime.currentTime().toString())
        print(self.lst)
        self.stringListModel.endResetModel ()


app = QApplication(sys.argv)
qb = BoxLayout()
qb.show()
sys.exit(app.exec_())
4

0 回答 0