第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

QAbstractTabelModel.data() 總是得到 index.row() == 0

QAbstractTabelModel.data() 總是得到 index.row() == 0

素胚勾勒不出你 2021-06-29 17:53:21
我已經(jīng)定義我的自定義QAbstrtactTableModelPython和實(shí)施columnCount(),rowCount(),data()和headerData()和也加入到一個(gè)函數(shù)add()新條目:import sysfrom PySide2.QtUiTools import QUiLoaderfrom PySide2.QtWidgets import QApplication, QMainWindowfrom PySide2.QtCore import QFile, QProcess, Signal,\    Slot, QObject, QThread, Qt, QAbstractTableModel, QModelIndex,\    QTimerimport randomclass TableModel(QAbstractTableModel):    def __init__(self, values):        QAbstractTableModel.__init__(self)        self.values = values    def columnCount(self, parent=QModelIndex()):        return 2    def rowCount(self, parent=QModelIndex()):        return len(self.values)    def data(self, index, role=Qt.DisplayRole):        print("called")        if 0 <= index.row() < self.rowCount() and 0 <= index.column() < self.columnCount():            if role == Qt.DisplayRole:                print(index.row())                if index.column() == 0:                    return list(self.values.keys())[index.row()]                else:                    return self.values[list(self.values.keys())[index.row()]]    def add(self, data):        self.values[data[0]] = data[1]    def headerData(self, section, orientation, role=Qt.DisplayRole):        if role == Qt.DisplayRole:            if orientation == Qt.Horizontal:                if section == 0:                    return "Parking,Meter"                elif section == 1:                    return "Revenue"class Monitor(QObject):    data_batch_ready = Signal(list)    def __init__(self, parent=None):        super(Monitor, self).__init__(parent)    @Slot(list)    def fill_batch(self):        my_data = []        for parking in range(4):            for index in range(10):                my_data.append([str(parking)+","+str(index), random.randint(1,101)])        self.data_batch_ready.emit(my_data)數(shù)據(jù)是一個(gè) python 字典,通過(guò)調(diào)用隨機(jī)函數(shù)進(jìn)行修改,該函數(shù)每 1 秒用 1 個(gè)條目填充字典,如下所示:"0,0":[隨機(jī)值]"0,1":[隨機(jī)值]"0,2":[隨機(jī)值]"1,0":[隨機(jī)值]"1,1":[隨機(jī)值]"1,2":[隨機(jī)值]rowCount()正確反映數(shù)據(jù)中的行數(shù)values,但tableView始終只顯示 1 行,并且data()僅請(qǐng)求index.row() == 0
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 200 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)