Python Forum
QModelIndex set Column in tablemodel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QModelIndex set Column in tablemodel
#1
Hello,

I use a table with tableview. In one of the Columns I present boolean values as checkbox. For this purpose I implimentet a checkbox as single GUI element. I will implement a progress that the checkbox in the table column changed his state if the gui checkbox changed his state. But the problem is. If I select the row, I select a column to and if I do not select the column with the checkbox  and I click the checkbox in the gui the wrong cell changed his value. So I create the follwing idea:


I create a new Function in the tablemodel and I set the column with the value for the correct one. But if I do that and I clicked the gui checkbox no values changed in the table.


def set_checkbox_clicked(self):
        index = self.dataTBL.selectedIndexes()[0]
        value = None
        model = self.dataTBL.model()
        if self.reBezChbx.isChecked():
            value = True
        else:
            value = False
        model.setDataCheckdata(index, value, QtCore.Qt.EditRole)
def setDataCheckdata(self, index, value, role=QtCore.Qt.EditRole):
        if role == QtCore.Qt.EditRole:
            row = index.row() #Selected row
            column = 2 #Only the thirt Column should set this value
            data = value
            self._data[row][column] = data
            self.dataChanged.emit(index, index)
            return True
I hope your able to understand my english ;)

greets niesel
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020