Exemple #1
0
 def setEditorData(self, editor, index):
     timestamp = index.model().data(index, Qt.EditRole)
     if timestamp == '':
         QStyledItemDelegate.setEditorData(self, editor, index)
     else:
         editor.setDateTime(
             QDateTime.fromSecsSinceEpoch(timestamp, spec=Qt.UTC))
Exemple #2
0
 def setEditorData(self, editor, index):
     account_currency = JalDB().get_account_currency(index.model().data(
         index.sibling(index.row(),
                       index.model().fieldIndex('account_id')),
         Qt.EditRole))
     editor.setFilterValue(account_currency)
     QStyledItemDelegate.setEditorData(self, editor, index)
    def paint(self, painter, option, index):
        """ Paint the items in the table.

            If the item referred to by <index> is a StarRating, we handle the
            painting ourselves. For the other items, we let the base class
            handle the painting as usual.

            In a polished application, we'd use a better check than the
            column number to find out if we needed to paint the stars, but
            it works for the purposes of this example.
        """
        if index.column() == 3:
            starRating = StarRating(index.data())

            # If the row is currently selected, we need to make sure we
            # paint the background accordingly.
            if option.state & QStyle.State_Selected:
                # The original C++ example used option.palette.foreground() to
                # get the brush for painting, but there are a couple of
                # problems with that:
                #   - foreground() is obsolete now, use windowText() instead
                #   - more importantly, windowText() just returns a brush
                #     containing a flat color, where sometimes the style
                #     would have a nice subtle gradient or something.
                # Here we just use the brush of the painter object that's
                # passed in to us, which keeps the row highlighting nice
                # and consistent.
                painter.fillRect(option.rect, painter.brush())

            # Now that we've painted the background, call starRating.paint()
            # to paint the stars.
            starRating.paint(painter, option.rect, option.palette)
        else:
            QStyledItemDelegate.paint(self, painter, option, index)
Exemple #4
0
 def setEditorData(self, editor, index):
     if index.column() == self._key:
         editor.setCurrentIndex(
             editor.findData(index.model().data(index, Qt.EditRole)))
     elif index.column() == self._value:
         type_idx = index.model().data(index.sibling(
             index.row(), self._key),
                                       role=Qt.EditRole)
         if self.types[type_idx][1] == "str":
             editor.setText(index.model().data(index, Qt.EditRole))
         elif self.types[type_idx][1] == "date":
             try:
                 timestamp = int(index.model().data(index, Qt.EditRole))
                 editor.setDateTime(
                     QDateTime.fromSecsSinceEpoch(timestamp, spec=Qt.UTC))
             except ValueError:
                 QStyledItemDelegate.setEditorData(self, editor, index)
         elif self.types[type_idx][1] == "float":
             try:
                 amount = float(index.model().data(index, Qt.EditRole))
             except (ValueError, TypeError):
                 amount = 0.0
             # QLocale().toString works in a bit weird way with float formatting - garbage appears after 5-6 decimal digits
             # if too long precision is specified for short number. So we need to be more precise setting precision.
             decimal_places = -decimal.Decimal(
                 str(amount).rstrip('0')).as_tuple().exponent
             editor.setText(QLocale().toString(amount, 'f', decimal_places))
         else:
             assert False, f"Unknown data type '{self.types[type_idx][1]}' in DataDelegate.setEditorData()"
     else:
         assert False, f"Delegate DataDelegate.setEditorData() called for not-initialized column {index.column()}"
 def setModelData(self, editor, model, index):
     """ Get the data from our custom editor and stuffs it into the model.
     """
     if index.column() == 3:
         model.setData(index, editor.starRating.starCount)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
Exemple #6
0
    def __init__(self, parent=None):
        QStyledItemDelegate.__init__(self, parent)

        self.timestamp_delegate = TimestampDelegate()
        self.float_delegate = FloatDelegate(2)
        self.default = QStyledItemDelegate()

        self.delegates = {}
Exemple #7
0
 def __init__(self, key_field, value_field, parent=None):
     QStyledItemDelegate.__init__(self, parent)
     self._key = key_field
     self._value = value_field
     self.types = {
         AssetData.RegistrationCode: (self.tr("reg.code"), "str"),
         AssetData.ExpiryDate: (self.tr("expiry"), "date"),
         AssetData.PrincipalValue: (self.tr("principal"), "float")
     }
Exemple #8
0
 def __init__(self,
              tolerance=None,
              allow_tail=True,
              colors=False,
              parent=None):
     self._parent = parent
     QStyledItemDelegate.__init__(self, parent)
     try:
         self._tolerance = int(tolerance)
     except (ValueError, TypeError):
         self._tolerance = self.DEFAULT_TOLERANCE
     self._allow_tail = allow_tail
     self._colors = colors
     self._color = None
     self._validator = QDoubleValidator()
     self._validator.setLocale(QLocale().system())
 def sizeHint(self, option, index):
     """ Returns the size needed to display the item in a QSize object. """
     if index.column() == 3:
         starRating = StarRating(index.data())
         return starRating.sizeHint()
     else:
         return QStyledItemDelegate.sizeHint(self, 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 __init__(self, parent=None):
     self._view = parent
     QStyledItemDelegate.__init__(self, parent)
Exemple #12
0
 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)
Exemple #13
0
 def __init__(self, display_format='%d/%m/%Y %H:%M:%S', parent=None):
     QStyledItemDelegate.__init__(self, parent)
     self._format = display_format
 def setEditorData(self, editor, index):
     """ Sets the data to be displayed and edited by our custom editor. """
     if index.column() == 3:
         editor.starRating = StarRating(index.data())
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)