def createEditor(self, parent, option, index): #pylint: disable=invalid-name """Return a combo box instance. The returned combo box instance should point to the proper relation model column. """ if not index.isValid(): return QItemDelegate.createEditor(self, parent, option, index) if not isinstance(index.model(), QSqlRelationalTableModel): # If not a QSqlRelationalTableModel, must be a proxy model. proxy_model = index.model() return self.createEditor(parent, option, proxy_model.mapToSource(index)) sql_model = index.model() child_model = sql_model.relationModel(index.column()) if not child_model: return QItemDelegate.createEditor(self, parent, option, index) column = child_model.fieldIndex( sql_model.relation(index.column()).displayColumn()) combobox = QComboBox(parent) combobox.setModel(child_model) combobox.setModelColumn(column) combobox.installEventFilter(self) return combobox
def createEditor(self, parent, option, index): delegate = self.delegates[index.column()] if delegate is not None: delegate.createEditor(parent, option,index) else: return QItemDelegate.createEditor(self, parent, option,index) # # # def commitAndCloseEditor(self): # editor = self.sender() # if isinstance(editor, (QTextEdit, QLineEdit)): # self.emit(SIGNAL("commitData(QWidget*)"), editor) # self.emit(SIGNAL("closeEditor(QWidget*)"), editor) # # # def setEditorData(self, editor, index): # textClassify = index.model().data(index, Qt.DisplayRole).toString() # if index.column() == TEU: # value = textClassify.replace(QRegExp("[., ]"), "").toInt()[0] # editor.setValue(value) # elif index.column() in (OWNER, COUNTRY): # i = editor.findText(textClassify) # if i == -1: # i = 0 # editor.setCurrentIndex(i) # elif index.column() == NAME: # editor.setText(textClassify) # elif index.column() == DESCRIPTION: # editor.setHtml(textClassify) # else: # QItemDelegate.setEditorData(self, editor, index) # # # def setModelData(self, editor, model, index): # QItemDelegate.setModelData(self, editor, model, index)
def createEditor(self, parent, option, index): if index.parent().isValid(): # item has a parent -> no SimulationModule # TODO implement dropdown menu if property is a dict return QItemDelegate.createEditor(self, parent, option, index) else: # no parent -> top of hierarchy return self.comboDel.createEditor(parent, option, index)
def createEditor(self, parent, option, index): """Create a ComboBox to edit the Target Quality.""" if index.column() == COLUMNS.QUALITY: editor = QComboBox(parent) self.parent.populate_quality_combo(combo=editor) editor.activated.connect(partial(self.update, editor, index)) return editor return QItemDelegate.createEditor(self, parent, option, index)
def init_validator(self): modes = ['vent', 'foot', 'bil', 'defrost', 'defog', 'trl', 'hil'] for i in modes: edit = self.RPM_tab.findChild(QLineEdit, i + '_edit') edit.setValidator(self.int_validator) edit.setMaxLength(4) value_delegate = QItemDelegate(self) value_delegate.createEditor = self.createEditor self.valve_table.setItemDelegateForColumn(1, value_delegate)
def createEditor(self, parent, option, index): if index.column() == QUALITY: editor = QComboBox(parent) self.parent.populate_presets(cb_presets=editor) editor.activated.connect(partial(self.update, editor, index)) return editor else: return QItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): if index.parent().isValid(): return QItemDelegate.createEditor(self, parent, option, index) else: # no parent -> top of hierarchy return None