QTableView not updated on dataChanged



  • Hello,
    I'm not able to update the layout of a QTableView when the Model data is changed.
    I tried with dataChanged.emit(index,index), with layoutChanged.emit() and also, as a last resort, with reset(). None of it worked.
    My code:

    class SettingsDialog(QDialog, settings_design.Ui_settingsDialog):
        def __init__(self):
            super(self.__class__, self).__init__()
            self.setupUi(self)
            self.weekdayTable = QTableView(self.weekdayPage)
            weekdayModel = self.loadMeetingData(self.meetingsData['weekdayList'])
          #weekdayModel.dataChanged.connect(self.updateTable)
            self.weekdayTable.setModel(weekdayModel)
       
        def updateTable(self):
            self.weekdayTable.repaint()
    
    class MeetingsModel(QStandardItemModel):
        def __init__(self, data, columns):
            QStandardItemModel.__init__(self, data, columns)
            with open('meetings.config.json') as f:
                self.meetingsData = json.load(f)
    
        def setData(self, index, value, other):
                   
            self.meetingsData['weekdayList'][int(index.row())][index.column()] = value
            with open('meetings.config.json', 'w+') as f:
                f.write(json.dumps(self.meetingsData))
    
            self.dataChanged.emit(index, index)
            # self.layoutChanged.emit(index, index)
            return True
    

    What am I doing wrong?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Something's not clear. Do you have anything that is shown at all ?

    In your code excerpt there's nothing related to the handling of the row/column count for example. Also your QTableView doesn't belong to any layout so are you resizing it somewhere ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.