Ejemplo n.º 1
0
 def setEditorData(self, editor: QWidget, index: QModelIndex):
     editor.blockSignals(True)
     try:
         editor.setValue(int(index.model().data(index)))
     except ValueError:
         pass  # If Label was deleted and UI not updated yet
     editor.blockSignals(False)
Ejemplo n.º 2
0
 def setEditorData(self, editor: QWidget, index: QModelIndex) -> None:
     editor.blockSignals(True)
     try:
         editor.setValue(float(index.model().data(index)))
     except ValueError:
         pass
     editor.blockSignals(False)
Ejemplo n.º 3
0
def set_widget_state(widget: QWidget, config: dict, widget_name=None):
    try:
        if widget_name is None:
            widget_name = widget.objectName()
        if widget_name not in config:
            return
        if isinstance(widget, QLineEdit):
            widget.setText(config[widget_name])
        elif isinstance(widget, QComboBox):
            widget.setUpdatesEnabled(False)
            bs = widget.blockSignals(True)
            widget.clear()
            widget.addItems(config[widget_name]['items'])
            widget.blockSignals(bs)
            widget.setUpdatesEnabled(True)
            widget.setCurrentIndex(config[widget_name]['index'])
            # Force index change event in the case of index=0
            if config[widget_name]['index'] == 0:
                widget.currentIndexChanged.emit(0)
        elif isinstance(widget, QtWidgets.QAbstractButton):
            widget.setChecked(config[widget_name])
        elif isinstance(widget, QPlainTextEdit) or isinstance(
                widget, QtWidgets.QTextEdit):
            widget.setPlainText(config[widget_name])
        elif isinstance(widget, QtWidgets.QSpinBox) or isinstance(
                widget, QtWidgets.QDoubleSpinBox):
            widget.setValue(config[widget_name])
    except:
        return
Ejemplo n.º 4
0
 def setEditorData(self, editor: QWidget, index: QModelIndex):
     editor.blockSignals(True)
     item = index.model().data(index)
     try:
         indx = self.items.index(item) if item in self.items else int(item)
         editor.setCurrentIndex(indx)
     except ValueError:
         pass
     editor.blockSignals(False)
Ejemplo n.º 5
0
 def setEditorData(self, editor: QWidget, index: QModelIndex):
     editor.blockSignals(True)
     item = index.model().data(index)
     try:
         indx = self.items.index(item) if item in self.items else int(item)
         editor.setCurrentIndex(indx)
     except ValueError:
         pass
     editor.blockSignals(False)
Ejemplo n.º 6
0
 def _write_to_widget(self, widget: QWidget, row_idx: Optional[int],
                      col_idx: int) -> None:
     if self._ignoring:
         return
     name = widget.metaObject().userProperty().name()
     cur_value = (QVariant() if row_idx is None else self._model.index(
         row_idx, col_idx).data(Qt.ItemDataRole.EditRole))
     prev_value = widget.property(name)
     if cur_value != prev_value:
         if isinstance(widget, QComboBox) and row_idx is not None:
             widget.blockSignals(True)
             cb_row_idx = widget.findText(cur_value)
             widget.setCurrentIndex(cb_row_idx)
             widget.blockSignals(False)
         widget.setProperty(name, cur_value)
Ejemplo n.º 7
0
 def setEditorData(self, editor: QWidget,
                   index: QtCore.QModelIndex) -> None:
     editor.blockSignals(True)
     data = int(index.model().data(index))
     editor.setCurrentIndex(data)
     editor.blockSignals(False)