Esempio n. 1
0
    def drawColorPie(self, painter: QPainter) -> None:
        radius: int = 95
        painter.save()
        painter.setPen(Qt.NoPen)

        rect: QRectF = QRectF(-radius, -radius, radius * 2, radius * 2)

        # 计算总范围角度,当前值范围角度,剩余值范围角度
        angleAll: float = 360.0 - self.__startAngle - self.__endAngle
        angleCurrent: float = angleAll * ((self.__value - self.__minValue) /
                                          (self.__maxValue - self.__minValue))
        angleOther: float = angleAll - angleCurrent

        # 绘制当前值饼圆
        painter.setBrush(self.__progressColor)
        painter.drawPie(rect, (270 - self.__startAngle - angleCurrent) * 16,
                        angleCurrent * 16)

        # 绘制剩余值饼圆
        painter.setBrush(self.__progressBgColor)
        painter.drawPie(
            rect, (270 - self.__startAngle - angleCurrent - angleOther) * 16,
            angleOther * 16)

        painter.restore()
Esempio n. 2
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 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))
Esempio n. 4
0
    def drawArc(self, painter: QPainter, radius: int, angle: float,
                arc_color: QColor) -> None:
        painter.save()
        painter.setPen(Qt.NoPen)

        smallradius: int = radius - self.__radiusWidth
        maxRaidus: int = radius + self.__shadowWidth
        minRadius: int = smallradius - self.__shadowWidth

        # 采用圆形渐变,形成光晕效果
        radialGradient: QRadialGradient = QRadialGradient(
            QPointF(0, 0), maxRaidus)
        color: QColor = arc_color
        lightColor: QColor = arc_color.name()

        color.setAlphaF(0)
        radialGradient.setColorAt(0, color)
        radialGradient.setColorAt(minRadius * 1.0 / maxRaidus, color)
        color.setAlphaF(0.5)
        radialGradient.setColorAt(smallradius * 1.0 / maxRaidus, color)

        radialGradient.setColorAt((smallradius + 1) * 1.0 / maxRaidus,
                                  lightColor)
        radialGradient.setColorAt((radius - 1) * 1.0 / maxRaidus, lightColor)
        radialGradient.setColorAt(radius * 1.0 / maxRaidus, color)
        color.setAlphaF(0)
        radialGradient.setColorAt(1, color)

        painter.setBrush(QBrush(radialGradient))
        painter.drawPie(-maxRaidus, -maxRaidus, maxRaidus * 2, maxRaidus * 2,
                        90 * 16, int(-angle * 16))
        painter.restore()
Esempio n. 5
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(painter.Antialiasing)

        #painter.setBrush(QBrush(Qt.black, Qt.NoBrush))
        #painter.drawRect(self.winBox)  # border

        # value selector indicator
        painter.setBrush(QBrush(Qt.black, Qt.SolidPattern))
        painter.drawPie(self.vIdBox, 16 * (degrees(self.vIdAng) - 22.5), 720)

        # value selector arc
        painter.setClipPath(self.vArcPath)
        painter.setPen(Qt.NoPen)
        arc = QConicalGradient(self.cen, self.e_ang)
        color = QColor()
        color.setHsv(self.hue, self.sat, 255)
        arc.setColorAt(1 - (self.e_ang - self.s_ang) / 360.0, color)
        arc.setColorAt(1, Qt.black)
        arc.setColorAt(0, Qt.black)
        painter.setBrush(arc)
        painter.drawPath(self.vArcPath)
        painter.setClipPath(self.vArcPath, Qt.NoClip)

        # color wheel
        painter.setPen(Qt.NoPen)
        painter.setBrush(self.cWhlBrush1)
        painter.drawEllipse(self.cWhBox)
        painter.setBrush(self.cWhlBrush2)
        painter.drawEllipse(self.cWhBox)

        # crosshairs
        painter.setClipPath(self.colWhlPath)
        painter.setBrush(QBrush(Qt.black, Qt.SolidPattern))
        chVert = QRectF(0, 0, 2, 20)
        chHort = QRectF(0, 0, 20, 2)
        chVert.moveCenter(self.chPt)
        chHort.moveCenter(self.chPt)
        painter.drawRect(chVert)
        painter.drawRect(chHort)

        # named color locations
        if self._showNames:
            painter.setClipPath(self.vArcPath, Qt.NoClip)
            painter.setPen(Qt.SolidLine)
            try:
                painter.drawPoints(*self._namedColorPts)  # PyQt
            except:
                painter.drawPoints(self._namedColorPts)  # PySide
Esempio n. 6
0
 def pieComponent(self):
     piePainter = QPainter(self)
     penPie = QPen()
     penPie.setWidth(0)
     penPie.setColor(
         QColor(self.rpb_pieColor[0], self.rpb_pieColor[1],
                self.rpb_pieColor[2]))
     piePainter.setRenderHint(QPainter.Antialiasing)
     piePainter.setPen(penPie)
     piePainter.setBrush(
         QColor(self.rpb_pieColor[0], self.rpb_pieColor[1],
                self.rpb_pieColor[2]))
     piePainter.drawPie(
         self.rpb_piePosX, self.rpb_piePosY,
         (self.rpb_Size - self.sizeFactor) * self.rpb_pieRatio,
         (self.rpb_Size - self.sizeFactor) * self.rpb_pieRatio,
         self.startPosition, self.rpb_value)