我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用PyQt5.QtCore.QAbstractItemModel()。
def __init__(self, parent=None, columns=None): if columns is not None: self.columns = columns QtCore.QAbstractItemModel.__init__(self, parent=parent) self.rootnode = VQTreeItem((), None) if self.editable is None: self.editable = [False, ] * len(self.columns)
def flags(self, index): if not index.isValid(): return 0 flags = QtCore.QAbstractItemModel.flags(self, index) col = index.column() if self.editable[col]: flags |= QtCore.Qt.ItemIsEditable if self.dragable: flags |= QtCore.Qt.ItemIsDragEnabled return flags
def __init__(self, rows=()): QtCore.QAbstractItemModel.__init__(self) # Make sure the rows are lists ( so we can mod them ) self.rows = [list(row) for row in rows] if self.editable is None: self.editable = [False, ] * len(self.columns)
def flags(self, index): if not index.isValid(): return 0 flags = QtCore.QAbstractItemModel.flags(self, index) col = index.column() if self.editable[col]: flags |= QtCore.Qt.ItemIsEditable if self.dragable: flags |= QtCore.Qt.ItemIsDragEnabled # | QtCore.Qt.ItemIsDropEnabled return flags # def data(self, index, role): # if not index.isValid(): # return None # item = index.internalPointer() # if role == QtCore.Qt.DisplayRole: # return item.data(index.column()) # if role == QtCore.Qt.UserRole: # return item # return None # def _vqt_set_data(self, row, col, value): # return False # def appends(self, rows):
def setModelData(self, editor: QCheckBox, model: QAbstractItemModel, index: QModelIndex): model.setData(index, editor.isChecked(), Qt.EditRole)
def setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex): model.setData(index, editor.value(), Qt.EditRole)
def setModelData(self, editor: QWidget, model: QAbstractItemModel, index: QModelIndex): if self.return_index: model.setData(index, editor.currentIndex(), Qt.EditRole) else: model.setData(index, editor.currentText(), Qt.EditRole)