How to make QAbstractTableModel 's data checkable

半腔热情 提交于 2019-12-06 13:39:34

Override the flags function in MyModel.

def flags(self, index)
    return super(MyModel, self).flags(index)|QtCore.Qt.ItemIsUserCheckable

This says that the index in your model is checkable.

Then override the data function.

def data(self,index, role = Qt.DisplayRole) :   
    if (role == Qt.DisplayRole):   
        return "Row{}, Column{}".format(index.row() + 1, index.column() +1)
    elif (role==Qt.CheckStateRole):
        # read from your data and return Qt.Checked or Unchecked
    return None

Finally, you need to implement the setData function.

def setData(self, index, value, role = Qt.EditRole):
    if (role==Qt.CheckStateRole):
        # Modify your data.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!