Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to change multiple cells in a tableview

How to change multiple cells in a tableview

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 569 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    Hi!
    I have a model inherited from QAbstractTableModel.
    I am trying to make changes to several cells, but when changing data for several cells, only one cell's display changes. How do I get the model to update data?

        def setData(self, index, value, role=QtCore.Qt.EditRole):
            if not index.isValid():
                return False
    
    
            if index.column() == 1:
    
                # if value == False:
                #     self.checked[index.row()] = False
                #     print(111)
                #     print(index.row())
                #     return True
    
                if self.checked[index.row()]:
                    self.checked[index.row()] = False
                    self.idChecked = -1
                else:
                    self.checked[index.row()] = True
                    if self.idChecked > -1:
                        self.checked[self.idChecked] = False
                        # self.itemData(self.lastIndex).__setitem__(1,1)
                        # self.setData(self.lastIndex,False, role)
                        # print(self.idChecked)
                        # print( self.checked[self.idChecked])
                    self.idChecked = index.row()
    
                    self.signalNeedUpdate.emit()
                    # self.dataChanged().emit(index, index)
                    # self.dataChanged().emit(index, index)
                    # self.beginResetModel()
                    # self.lastIndex = index
                # self.checked[index.row()] = value
                # self.dataChanged().emit(index, index)
                return True
    
            return False
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mikeeeeee
      wrote on last edited by
      #2

      Replacing models for tableview helps. But there are probably better solutions.

      JonBJ 1 Reply Last reply
      0
      • M Mikeeeeee

        Replacing models for tableview helps. But there are probably better solutions.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Mikeeeeee

        I am trying to make changes to several cells, but when changing data for several cells, only one cell's display changes. How do I get the model to update data?

        If you are saying you have a setData() which alters more than one data item, or not the item indicated by the incoming index parameter, then you must emit dataChanged for the index(es) which have been changed, so that the view knows to update.

        1 Reply Last reply
        1

        • Login

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