Esempio n. 1
0
    def createEditor(self, parent, option, index):
        """
        Create for the display and interaction with the user an editor.

        @param QtGui.QWidget parent: The parent object (probably QTableView)
        @param QtGui.QStyleOptionViewItemV4 option: This is a setting option which you can use for
                                                    style configuration.
        @param QtCore.QModelIndex index: That index will be passed by the model object of the
                                         QTableView to the delegated object. This index contains
                                         information about the selected current cell.

        An editor can be in principle any QWidget, which you want to use to display the current
        (model-)data. Therefore the editor is like a container, which handles the passed entries
        from the user interface and should save the data to the model object of the QTableWidget.
        The setEditorData function reads data from the model.

        Do not save the created editor as a class variable! This consumes a lot of unneeded memory.
        It is way better to create an editor if it is needed. The inherent function closeEditor()
        of QStyledItemDelegate takes care of closing and destroying the editor for you, if it is not
        needed any longer.
        """
        editor = ScienDSpinBox(parent=parent)
        if 'min' in self.item_dict:
            editor.setMinimum(self.item_dict['min'])
        if 'max' in self.item_dict:
            editor.setMaximum(self.item_dict['max'])
        if 'dec' in self.item_dict:
            editor.setDecimals(self.item_dict['dec'])
        if 'unit' in self.item_dict:
            editor.setSuffix(self.item_dict['unit'])
        editor.setGeometry(option.rect)
        editor.editingFinished.connect(self.commitAndCloseEditor)
        return editor
Esempio n. 2
0
    def createEditor(self, parent, option, index):
        """ Create for the display and interaction with the user an editor.

        @param QtGui.QWidget parent: The parent object, here QTableWidget
        @param QtGui.QStyleOptionViewItemV4 option: This is a setting option
                                                    which you can use for style
                                                    configuration.
        @param QtCore.QModelIndex index: That index will be passed by the model
                                         object of the QTableWidget to the
                                         delegated object. This index contains
                                         information about the selected current
                                         cell.

        An editor can be in principle any QWidget, which you want to use to
        display the current (model-)data. Therefore the editor is like a
        container, which handles the passed entries from the user interface and
        should save the data to the model object of the QTableWidget. The
        setEditorData function reads data from the model.

        Do not save the created editor as a class variable! This consumes a lot
        of unneeded memory. It is way better to create an editor if it is
        needed. The inherent function closeEditor() of QStyledItemDelegate
        takes care of closing and destroying the editor for you, if it is not
        needed any longer.
        """
        editor = ScienDSpinBox(parent=parent)
        editor.setMinimum(self.item_dict['min'])
        editor.setMaximum(self.item_dict['max'])
        editor.setSingleStep(self.item_dict['view_stepsize'])
        editor.setDecimals(self.item_dict['dec'])
        editor.installEventFilter(self)
        editor.setValue(self.item_dict['init_val'])
        editor.setMaximumHeight(100)
        return editor
    def createEditor(self, parent, option, index):
        """ Create for the display and interaction with the user an editor.

        @param QtGui.QWidget parent: The parent object, here QTableWidget
        @param QtGui.QStyleOptionViewItemV4 option: This is a setting option
                                                    which you can use for style
                                                    configuration.
        @param QtCore.QModelIndex index: That index will be passed by the model
                                         object of the QTableWidget to the
                                         delegated object. This index contains
                                         information about the selected current
                                         cell.

        An editor can be in principle any QWidget, which you want to use to
        display the current (model-)data. Therefore the editor is like a
        container, which handles the passed entries from the user interface and
        should save the data to the model object of the QTableWidget. The
        setEditorData function reads data from the model.

        Do not save the created editor as a class variable! This consumes a lot
        of unneeded memory. It is way better to create an editor if it is
        needed. The inherent function closeEditor() of QStyledItemDelegate
        takes care of closing and destroying the editor for you, if it is not
        needed any longer.
        """
        editor = ScienDSpinBox(parent=parent)
        editor.setMinimum(self.item_dict['min'] / self.norm_val)
        editor.setMaximum(self.item_dict['max'] / self.norm_val)
        editor.setSingleStep(self.item_dict['view_stepsize'] / self.norm_val)
        editor.setDecimals(self.item_dict['dec'])
        editor.installEventFilter(self)
        editor.setValue(self.item_dict['init_val'] / self.norm_val)
        editor.setMaximumHeight(100)
        return editor
Esempio n. 4
0
 def paint(self, painter, option, index):
     painter.save()
     r = option.rect
     painter.translate(r.topLeft())
     widget = ScienDSpinBox()
     if 'dec' in self.item_dict:
         widget.setDecimals(self.item_dict['dec'])
     if 'unit' in self.item_dict:
         widget.setSuffix(self.item_dict['unit'])
     widget.setGeometry(r)
     widget.setValue(index.data(self._access_role))
     widget.render(painter)
     painter.restore()
Esempio n. 5
0
    def __init__(self, parent=None, parameters_dict=None):
        super().__init__(parent)
        if parameters_dict is None:
            self._parameters = OrderedDict()
        else:
            self._parameters = parameters_dict

        self._width_hint = 90 * len(self._parameters)
        self._ach_widgets = OrderedDict()

        main_layout = QtGui.QHBoxLayout()
        for param in self._parameters:
            label = QtGui.QLabel(param)
            label.setAlignment(QtCore.Qt.AlignCenter)
            if self._parameters[param]['type'] == float:
                widget = ScienDSpinBox()
                widget.setMinimum(self._parameters[param]['min'])
                widget.setMaximum(self._parameters[param]['max'])
                widget.setDecimals(6, False)
                widget.setValue(self._parameters[param]['init'])
                widget.setSuffix(self._parameters[param]['unit'])
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.editingFinished.connect(self.editingFinished)
            elif self._parameters[param]['type'] == int:
                widget = ScienSpinBox()
                widget.setValue(self._parameters[param]['init'])
                widget.setMinimum(self._parameters[param]['min'])
                widget.setMaximum(self._parameters[param]['max'])
                widget.setSuffix(self._parameters[param]['unit'])
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.editingFinished.connect(self.editingFinished)
            elif self._parameters[param]['type'] == str:
                widget = QtGui.QLineEdit()
                widget.setText(self._parameters[param]['init'])
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.editingFinished.connect(self.editingFinished)
            elif self._parameters[param]['type'] == bool:
                widget = QtGui.QCheckBox()
                widget.setChecked(self._parameters[param]['init'])
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.stateChanged.connect(self.editingFinished)
            elif issubclass(self._parameters[param]['type'], Enum):
                widget = QtGui.QComboBox()
                for option in self._parameters[param]['type']:
                    widget.addItem(option.name, option)
                widget.setCurrentText(self._parameters[param]['init'].name)
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.currentIndexChanged.connect(self.editingFinished)

            self._ach_widgets[param] = {'label': label, 'widget': widget}

            v_layout = QtGui.QVBoxLayout()
            v_layout.addWidget(label)
            v_layout.addWidget(widget)
            v_layout.setAlignment(label, QtCore.Qt.AlignHCenter)
            v_layout.setAlignment(widget, QtCore.Qt.AlignHCenter)
            main_layout.addLayout(v_layout)

        main_layout.addStretch(1)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)