def createEditor(self, parent, option, index): if index.column() == 0: pushButton = QPushButton(parent) pushButton.hide() #pushButton.setIcon(QtGui.QPixmap(":/spotify/resources/icons/play_lgrey.png"), QtGui.QIcon.Normal, # QtGui.QIcon.Off) return pushButton else: return QStyledItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): """ Creates and returns the custom StarEditor object we'll use to edit the StarRating. """ if index.column() == 3: editor = StarEditor(parent) editor.editingFinished.connect(self.commitAndCloseEditor) return editor else: return QStyledItemDelegate.createEditor(self, parent, option, index)
def testIntDelegate(self): """PYSIDE-1250: When creating a QVariant, use int instead of long long for anything that fits into a int. Verify by checking that a spin box is created as item view editor for int.""" item = QStandardItem() item.setData(123123, Qt.EditRole) # <-- QVariant conversion here model = QStandardItemModel() model.appendRow(item) style_option = QStyleOptionViewItem() delegate = QStyledItemDelegate() editor = delegate.createEditor(None, style_option, model.index(0, 0)) self.assertEqual(type(editor), QSpinBox)
def createEditor(self, parent: QModelIndex, option: QStyleOptionViewItem, index: QModelIndex) -> QWidget: """ Creates the widget used to change data from the model and can be reimplemented to customize editing behavior :param parent: Parent of the editor. :type parent: QModelIndex :param option: Option of the editor. :type option: QStyleOptionViewItem :param index: Index of the editor. :type index: QModelIndex :return: Editor for PropModel :rtype: QWidget """ data = index.internalPointer() if index.column() == 1 and isinstance( data, Property) and data.getType() == bool: return None if type(data) == Property: if index.column() == 1: t = data.getType() if t == str: return QLineEdit(parent) elif t == int: return QSpinBox(parent) elif t == bool: return QCheckBox(parent) elif t == float: return QDoubleSpinBox(parent) elif issubclass(t, Enum): editor = QComboBox(parent) t = type(data.getValue()) for i, option in enumerate(t): editor.addItem(option.name, option) return editor else: pass return QStyledItemDelegate.createEditor(self, parent, option, index)
def createEditor(self, parent, option, index): if index.model().get_item(index).waiting_evaluation: return AskVerdict(parent, self) else: return QStyledItemDelegate.createEditor(self, parent, option, index)
class KnechtValueDelegate(QStyledItemDelegate): def __init__(self, view): """ Basic item delegate that returns the views default item delegate or depending on the item type column: an appropriate custom render setting item delegate. :param modules.itemview.treeview.KnechtTreeView view: View we replace delegates in """ super(KnechtValueDelegate, self).__init__(view) self.view = view self.default_delegate = QStyledItemDelegate(view) self.setting_delegate = None def createEditor(self, parent, option, index): # ---- Default behaviour ---- if not self._index_is_custom_setting(index): return self.default_delegate.createEditor(parent, option, index) # ---- Custom behaviour ---- return self.setting_delegate.create_editor(parent, option, index) def setEditorData(self, editor, index): # ---- Default behaviour ---- if not self._index_is_custom_setting(index): return self.default_delegate.setEditorData(editor, index) # ---- Custom behaviour --- self.setting_delegate.set_editor_data(editor, index) def setModelData(self, editor, model, index): # ---- Default behaviour ---- if not self._index_is_custom_setting(index): return self.default_delegate.setModelData(editor, model, index) # ---- Custom behaviour --- self.setting_delegate.set_model_data(editor, model, index) def updateEditorGeometry(self, editor, option, index): # ---- Default behaviour ---- if not self._index_is_custom_setting(index): return self.default_delegate.updateEditorGeometry( editor, option, index) # ---- Custom behaviour --- editor.setGeometry(option.rect) def _index_is_custom_setting(self, index: QModelIndex): src_index = index.model().mapToSource(index) item: KnechtItem = index.model().sourceModel().get_item(src_index) setting_type = item.data(Kg.TYPE) if item.userType in [Kg.output_item]: self.setting_delegate = OutputDirButton(self.view) return True if item.userType in [Kg.plmxml_item]: self.setting_delegate = InputFileButton(self.view) return True if item.userType == Kg.render_setting and setting_type in RENDER_SETTING_MAP.keys( ): self.setting_delegate = RENDER_SETTING_MAP[setting_type](self.view) return True return False