0

I have a custom QTableModel which I'm displaying using QTableView in PyQt. I have some fields set as checkable, and I want to add check all and check none buttons. I feel there should be a way to cause the setData() to be called from the code in such a way that the checked state will change as well as the code I have already written in setData(). Is there in fact a way to do this?

Here is the setData I'm using, as requested:

if role == Qt.CheckStateRole:
        row = index.row()
        column = index.column()

        if row == 0 and column != 0:
            self._data.parsingConfiguration['columnEnabled'][column-1] = True if value == Qt.Checked else False
            self.dataChanged.emit(self.createIndex(1, column), self.createIndex(len(self._data.data),column))

            if column-1 == self._data.parsingConfiguration['groupNumberColumn']:
                self.setGroupNumber(self.getFirstEnabledMember())
            elif column-1 == self._data.parsingConfiguration['timeStepColumn']:
                self.setTimeStep(self.getFirstEnabledMember())
            self.emit(SIGNAL("layoutChanged()"))
            return True
        if column == 0 and row != 0:
            self._data.parsingConfiguration['rowEnabled'][row-1] = True if value == Qt.Checked else False
            self.dataChanged.emit(self.createIndex(row, 1), self.createIndex(row, self._data.numColumns+1))
            return True
        return False
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Andrew Ring
  • 3,185
  • 1
  • 23
  • 28
  • 1
    Just to clarify: you want two widgets outside your QTableView whose activation changing the 'checked' state of your model items, right ? Could you post you `setData` ? – Pierre GM Aug 18 '12 at 16:15
  • I second @PierreGM. Show code. This is too vauge. – jdi Aug 19 '12 at 04:31
  • Code added, sorry I wasn't more clear. Ultimately I want to know if there is a feasible way to call setData myself so I can keep code in a single place. – Andrew Ring Aug 21 '12 at 21:09

1 Answers1

0

After a little more trial and error I discovered that I can change the data which is informing the data function's return on QCheckState, then emit a layoutChanged() signal from the model. This still does not call the setData method, and did require separate functions be written (thus not completing my initial goal), however it does achieve the desired results from a user perspective.

Andrew Ring
  • 3,185
  • 1
  • 23
  • 28