Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView not updated on dataChanged

QTableView not updated on dataChanged

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtableview
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • tuxumT Offline
    tuxumT Offline
    tuxum
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved