def setModelData(self, editor, model, index): if isinstance(editor, PathEditor): cfg_path = nm.settings().cfg_path model.setData(index, editor.path) self.reload_settings = (cfg_path != nm.settings().cfg_path) else: QStyledItemDelegate.setModelData(self, editor, model, index)
def __init__(self, parent=None, check_for_ros_names=True, dec_ascent=False, is_node=False, palette=None): QStyledItemDelegate.__init__(self, parent) self._check_for_ros_names = check_for_ros_names self._cached_size = None self._red_ascent = 4 if not dec_ascent else 2 self._dec_ascent = dec_ascent self._is_node = is_node self._palette = palette
def paint(self, painter, option, index): if not index.parent().isValid(): # Root level option.font.setWeight(QFont.Bold) if index.parent().isValid() and not index.parent().parent().isValid(): # Hardware interface level option.font.setItalic(True) option.font.setWeight(QFont.Bold) QStyledItemDelegate.paint(self, painter, option, index)
def createEditor(self, parent, option, index): ''' Creates a editor in the TreeView depending on type of the settings data. ''' item = self._itemFromIndex(index) if item.edit_type() == SettingsValueItem.EDIT_TYPE_AUTODETECT: if isinstance(item.value(), bool): box = QCheckBox(parent) box.setFocusPolicy(Qt.StrongFocus) box.setAutoFillBackground(True) box.stateChanged.connect(self.edit_finished) return box elif isinstance(item.value(), int): box = QSpinBox(parent) box.setValue(item.value()) if not item.value_min() is None: box.setMinimum(item.value_min()) if not item.value_max() is None: box.setMaximum(item.value_max()) return box elif item.edit_type() == SettingsValueItem.EDIT_TYPE_FOLDER: editor = PathEditor(item.value(), parent) editor.editing_finished_signal.connect(self.edit_finished) return editor elif item.edit_type() == SettingsValueItem.EDIT_TYPE_LIST: box = QComboBox(parent) box.addItems(item.value_list()) index = box.findText(item.value()) if index >= 0: box.setCurrentIndex(index) box.setEditable(False) return box return QStyledItemDelegate.createEditor(self, parent, option, index)