def setModelData(self, editor: QComboBox, model: QAbstractTableModel, index: QModelIndex) -> None: """ Update the model data at the given index from the editor value. Derived function. :param editor: data provider :param model: data storage :param index: index where data has to be updated :return: Nothing """ self.logger.debug("Updating model data for index [{}, {}]: {}".format( index.column(), index.row(), editor.currentText())) if index.isValid() and index.column( ) == 1 and not self.__only_numbers: # only type can is editable model.setData(index, editor.currentText()) return super().setModelData(editor, model, index)
def setModelData(self, editor: QWidget, model: QAbstractTableModel, index: QModelIndex) -> None: """ Update the model data at the given index from the editor value. Derived function. :param editor: data provider :param model: data storage :param index: index where data has to be updated :return: Nothing """ if index.isValid(): if index.column() in (0, 1): model.setData(index, editor.isChecked()) return if index.column() == 4: model.setData(index, editor.color()) return super().setModelData(editor, model, index)
def setData(self, index, value, role): if role == Qt.EditRole and index.isValid(): task = self.todoList[index.row()] if index.column() == 0: if value == self.tr("未开始"): task["finishment"] = 0 elif value == self.tr("已完成"): task["finishment"] = 100 else: task["finishment"] = 50 else: assert index.column() == 1 task["subject"] = value self.dataChanged.emit(index, index) self.taskUpdated.emit(task["id"]) return True return QAbstractTableModel.setData(self, index, value, role)