Exemple #1
0
    def paintEvent(self, event):
        rect = QRect(10, 20, 80, 60)

        path = QPainterPath()
        path.moveTo(20, 80)
        path.lineTo(20, 30)
        path.cubicTo(80, 0, 50, 50, 80, 80)

        startAngle = 30 * 16
        arcLength = 120 * 16

        painter = QPainter(self)
        painter.setPen(self.pen)
        painter.setBrush(self.brush)
        if self.antialiased:
            painter.setRenderHint(QPainter.Antialiasing)

        for x in range(0, self.width(), 100):
            for y in range(0, self.height(), 100):
                painter.save()
                painter.translate(x, y)
                if self.transformed:
                    painter.translate(50, 50)
                    painter.rotate(60.0)
                    painter.scale(0.6, 0.9)
                    painter.translate(-50, -50)

                if self.shape == RenderArea.Line:
                    painter.drawLine(rect.bottomLeft(), rect.topRight())
                elif self.shape == RenderArea.Points:
                    painter.drawPoints(RenderArea.points)
                elif self.shape == RenderArea.Polyline:
                    painter.drawPolyline(RenderArea.points)
                elif self.shape == RenderArea.Polygon:
                    painter.drawPolygon(RenderArea.points)
                elif self.shape == RenderArea.Rect:
                    painter.drawRect(rect)
                elif self.shape == RenderArea.RoundedRect:
                    painter.drawRoundedRect(rect, 25, 25, Qt.RelativeSize)
                elif self.shape == RenderArea.Ellipse:
                    painter.drawEllipse(rect)
                elif self.shape == RenderArea.Arc:
                    painter.drawArc(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Chord:
                    painter.drawChord(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Pie:
                    painter.drawPie(rect, startAngle, arcLength)
                elif self.shape == RenderArea.Path:
                    painter.drawPath(path)
                elif self.shape == RenderArea.Text:
                    painter.drawText(rect, Qt.AlignCenter,
                                     "PySide 2\nQt %s" % qVersion())
                elif self.shape == RenderArea.Pixmap:
                    painter.drawPixmap(10, 10, self.pixmap)

                painter.restore()

        painter.setPen(self.palette().dark().color())
        painter.setBrush(Qt.NoBrush)
        painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1))
 def shape_to_pixelmap(item_type, pen, brush, shape) -> QPixmap:
     pixmap = QPixmap(50, 50)
     pixmap.fill(Qt.transparent)
     painter = QPainter(pixmap)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setPen(pen)
     painter.setBrush(brush)
     if item_type == QGraphicsRectItem.type(QGraphicsRectItem()):
         painter.drawRect(QRect(10, 15, 30, 20))
     elif item_type == QGraphicsEllipseItem.type(QGraphicsEllipseItem()):
         painter.drawEllipse(QRect(10, 10, 30, 30))
     elif item_type == QGraphicsPolygonItem.type(QGraphicsPolygonItem()):
         if shape.polygon().size() == 3:
             painter.drawPolygon(QPolygon([QPoint(10, 40), QPoint(40, 40), QPoint(25, 10)]))
         else:
             painter.drawPolygon(QPolygon([QPoint(12, 40), QPoint(23, 36),
                                           QPoint(37, 24), QPoint(23, 12), QPoint(7, 16)]))
     elif item_type == QGraphicsLineItem.type(QGraphicsLineItem()):
         painter.drawLine(QLine(10, 40, 40, 10))
     return pixmap
Exemple #3
0
    def paintEvent(self, pe) -> None:

        mainradius, fontsizefactor, center_x, center_y_pp, width = self.computeCenter(
        )

        painter = QPainter(self)
        # So that we can use the background color
        painter.setBackgroundMode(Qt.OpaqueMode)
        # Smooth out the circle
        painter.setRenderHint(QPainter.Antialiasing)
        # Use background color
        textBgColor = QColor(painter.background().color())
        # print("bgcolor = ", bgColor)
        bgColor = QColor("transparent")
        pointColor = QColor(painter.pen().color())

        self.pointColor = pointColor
        self.bgColor = textBgColor

        alpha = 150

        if self.parent().displayPp == 'all' or self.parent(
        ).displayPp == self.io:
            pointColor.setAlpha(255)
        else:
            pointColor.setAlpha(alpha)

        # draw text
        if not self._hasFixedFontSize:
            fontsize = mainradius * fontsizefactor
        else:
            fontsize = self._fixedFontSize
        self.fontsize = fontsize
        textRect_ = QtCore.QRectF(0, center_y_pp - mainradius - 2 * fontsize,
                                  width, 2 * fontsize)
        f = painter.font()
        f.setPointSizeF(fontsize)

        # self._io = 'in'
        if self.io == 'out':
            fm = QFontMetrics(f).boundingRect(self._text)
            # print("fm = ", fm)
            painter.setBrush(pointColor)
            painter.setPen(QPen(pointColor))
            painter.drawRect(
                QtCore.QRectF(center_x - fm.width() / 2,
                              center_y_pp - mainradius - 2 * fontsize,
                              fm.width(), fm.height()))
            painter.setPen(QPen(textBgColor))

        painter.setFont(f)
        painter.setBackgroundMode(Qt.TransparentMode)
        painter.drawText(textRect_, Qt.AlignHCenter | Qt.AlignTop, self._text)

        # draw hexagon
        painter.setBrush(bgColor)
        painter.setPen(pointColor)
        painter.drawPolygon(
            self.createPoly(6, mainradius, center_x, center_y_pp))

        # draw outer circle
        radius_outer = mainradius * .8
        if self.title not in implementedPatchPoints:
            painter.setBrush(QtGui.QBrush(QtGui.QColor(int("0x999999", 0))))
        painter.drawEllipse(QtCore.QPointF(center_x, center_y_pp),
                            radius_outer, radius_outer)

        # draw inner circle
        radius_inner = mainradius * .5
        # painter.setBrush(QBrush(pointColor))
        painter.setBrush(QColor(self._ppColor))
        painter.drawEllipse(QtCore.QPointF(center_x, center_y_pp),
                            radius_inner, radius_inner)