Example #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
Example #2
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()