mardi 1 mai 2018

PyQt QAbstractTableModel checkbox not tickable

I am using own table model with QAbstractTableModel, where I have first col with checkbox (checkable cause flags Qt.ItemIsUserCheckable | Qt.ItemIsSelectable | Qt.ItemIsEnabled). I have trouble when I am trying use checkboxes, cause they are not checkable (can not make tick or untick in them) in showed table. What am I doing wrong? I am using this methods in own table model class:

def data(self, index, role):#=Qt.DisplayRole):

    row = index.row()
    col = index.column()

    if role == Qt.DisplayRole:
        return '{0}'.format(self.tableData[row][col])

    if role == Qt.CheckStateRole: 
        if col == 0:
            return Qt.Unchecked
        else: 
            return None

def setData(self, index, value, role):
    if not index.isValid():
       return False

    if (role == Qt.CheckStateRole):
        if (index.data(Qt.CheckStateRole) == Qt.Checked):
            return True
        else:
            return False
    else:
        return False




Aucun commentaire:

Enregistrer un commentaire