Beispiel #1
0
    def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex):
        """Renders the delegate using the given painter and style option for the item specified by index.

        :param painter: A QPainter object to draw
        :param option: Options to describe what should be drawn
        :param index: _description_
        """
        if not index.isValid():
            return

        # Initialize the style options. This is not very Pythonic as it uses C++
        # references under the hood so opt is affected by the second call
        opt = QStyleOptionViewItem(option)
        self.initStyleOption(opt, index)

        # Standard setup, paint, restore operation
        painter.save()
        try:
            painter.setClipRect(opt.rect)
            foreground_colour, background_colour = index.data(Qt.ForegroundRole), index.data(Qt.BackgroundRole)
            if foreground_colour is not None:
                painter.setPen(foreground_colour)
            if background_colour is not None:
                painter.fillRect(option.rect, background_colour)
            padding = self._padding
            opt.rect = option.rect.adjusted(padding, padding, -padding, -padding)
            painter.drawText(opt.rect, int(Qt.AlignLeft | Qt.AlignVCenter),
                             opt.fontMetrics.elidedText(opt.text, Qt.ElideRight, opt.rect.width()))
        finally:
            painter.restore()
    def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget):
        """
        Paint

        Parameters
        ----------
        painter : QPainter
        option : QStyleOptionGraphicsItem
        widget : QWidget
        """
        painter.setClipRect(option.exposedRect)
        ConnectionPainter.paint(painter, self._connection, self._style)
Beispiel #3
0
    def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem,
              widget: QWidget):
        """
        Paint

        Parameters
        ----------
        painter : QPainter
        option : QStyleOptionGraphicsItem
        widget : QWidget
        """
        from .node_painter import NodePainter
        # TODO
        painter.setClipRect(option.exposedRect)
        NodePainter.paint(
            painter,
            self._node,
            self._scene,
            node_style=self._style.node,
            connection_style=self._style.connection,
        )
Beispiel #4
0
 def paintEvent(self, e):
     cr = self.contentsRect()
     painter = QPainter(self)
     painter.setClipRegion(e.region())
     # if self.__data.isDown:
     #     qDrawWinButton(
     #         painter, 0, 0, self.width(), self.height(), self.palette(), True
     #     )
     painter.save()
     if self.__data.isDown:
         shiftSize = buttonShift(self)
         painter.translate(shiftSize.width(), shiftSize.height())
     painter.setClipRect(cr)
     self.drawContents(painter)
     if not self.__data.icon.isNull():
         iconRect = QRect(cr)
         iconRect.setX(iconRect.x() + self.margin())
         if self.__data.itemMode != QwtLegendData.ReadOnly:
             iconRect.setX(iconRect.x() + BUTTONFRAME)
         iconRect.setSize(self.__data.icon.size())
         iconRect.moveCenter(QPoint(iconRect.center().x(), cr.center().y()))
         painter.drawPixmap(iconRect, self.__data.icon)
     painter.restore()
Beispiel #5
0
 def paintEvent(self, event):
     QFrame.paintEvent(self, event)
     painter = QPainter(self)
     painter.setClipRect(self.contentsRect())
     self.drawContents(painter)