Exemplo n.º 1
0
    def drawText(self, painter: QPainter) -> None:
        painter.save()
        painter.setPen(Qt.NoPen)

        font: QFont = QFont()
        font.setBold(True)
        font.setPointSize(10)
        painter.setFont(font)

        now: QDateTime = QDateTime.currentDateTime()
        fm: QFontMetricsF = QFontMetricsF(font)
        textList: List[AnyStr] = [
            now.toString("MM月dd日yyyy"),
            now.toString("hh:mm:ss.zzz")
        ]

        # 绘制文本路径
        textPath: QPainterPath = QPainterPath()
        textPath.addText(-fm.width(textList[0]) / 2.0, -fm.lineSpacing() / 2.0,
                         font, textList[0])
        textPath.addText(-fm.width(textList[1]) / 2.0,
                         fm.lineSpacing() / 2.0, font, textList[1])

        strokeColor: QColor = self.__textColor.light(80)
        strokeColor.setAlphaF(0.2)
        painter.strokePath(
            textPath,
            QPen(strokeColor, self.__shadowWidth, Qt.SolidLine, Qt.RoundCap,
                 Qt.RoundJoin))
        painter.setBrush(self.__textColor)
        painter.drawPath(textPath)

        painter.restore()
Exemplo 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 paint(self,
              painter: QPainter,
              option: QStyleOptionGraphicsItem,
              widget: Optional[QWidget] = ...):
        painter.setPen(self.pen())
        brush = self.brush()
        painter.setBrush(brush)
        path = QPainterPath()
        path.moveTo(self.__sourcePoint)
        path.cubicTo(self._edge1, self._edge2, self.__destPoint)
        if self._isDigraph:
            painter.setBrush(Qt.gray)
            painter.drawPolygon(self.drawArrow())
            path.addPolygon(self.drawArrow())
        painter.setBrush(Qt.NoBrush)
        if self.isSelected():
            pen = painter.pen()
            pen.setColor(self.get_isSelectedPenColor())
        else:
            pen = painter.pen()
            pen.setColor(self.get_noSelectedPenColor())
        painter.setPen(pen)

        painter.drawPath(path)
        self.__path = path
Exemplo n.º 4
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 drawOverlay(self, painter: QPainter) -> None:
        if not self.__showOverlay: return

        radius: int = 80
        painter.save()
        painter.setPen(Qt.NoPen)

        smallCircle: QPainterPath = QPainterPath()
        bigCircle: QPainterPath = QPainterPath()
        radius -= 1
        smallCircle.addEllipse(-radius, -radius, radius * 2, radius * 2)
        radius *= 2
        bigCircle.addEllipse(-radius, -radius + 140, radius * 2, radius * 2)

        # 高光的形状为小圆扣掉大圆的部分
        highlight: QPainterPath = smallCircle - bigCircle

        linearGradient: QLinearGradient = QLinearGradient(0, -radius / 2, 0, 0)
        self.__overlayColor.setAlpha(100)
        linearGradient.setColorAt(0.0, self.__overlayColor)
        self.__overlayColor.setAlpha(30)
        linearGradient.setColorAt(1.0, self.__overlayColor)
        painter.setBrush(linearGradient)
        painter.rotate(-20)
        painter.drawPath(highlight)

        painter.restore()
Exemplo n.º 6
0
    def paintEvent(self, *args):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.setBrush(Qt.black)
        painter.setPen(QPen(Qt.transparent))
        for block in self.blocks:
            painter.drawRect(block)

        if self.debug:
            lines = list()
            points = list()
            for p1 in self.graph:
                for p2 in self.graph[p1]:
                    lines.append(QLine(*p1, *p2))
                    points.append(QPoint(*p1))
                    points.append(QPoint(*p2))

            painter.setPen(QPen(Qt.black))
            painter.drawLines(lines)
            painter.setPen(QPen(Qt.red, 3))
            painter.drawPoints(points)

        if self.path:
            painter.setPen(QPen(Qt.green))
            painter.setBrush(Qt.transparent)
            p = QPainterPath()
            p.moveTo(*self.path[0])
            for point in self.path:
                p.lineTo(*point)
            painter.drawPath(p)
Exemplo n.º 7
0
    def paintEvent(self, event):
        super(BubbleLabel, self).paintEvent(event)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)  # 抗锯齿

        rectPath = QPainterPath()  # 圆角矩形
        triPath = QPainterPath()  # 底部三角形

        height = self.height() - 8  # 往上偏移8
        rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5)
        x = self.width() / 5 * 4
        triPath.moveTo(x, height)  # 移动到底部横线4/5处
        # 画三角形
        triPath.lineTo(x + 6, height + 8)
        triPath.lineTo(x + 12, height)

        rectPath.addPath(triPath)  # 添加三角形到之前的矩形上

        # 边框画笔
        painter.setPen(QPen(self.BorderColor, 1, Qt.SolidLine,
                            Qt.RoundCap, Qt.RoundJoin))
        # 背景画刷
        painter.setBrush(self.BackgroundColor)
        # 绘制形状
        painter.drawPath(rectPath)
        # 三角形底边绘制一条线保证颜色与背景一样
        painter.setPen(QPen(self.BackgroundColor, 1,
                            Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(x, height, x + 12, height)
Exemplo n.º 8
0
    def paintEvent(self, event: QPaintEvent):
        super().paintEvent(event)

        if self._viewport_anchoring_scheduled:
            self._anchor_viewport()
            self._viewport_anchoring_scheduled = False

        painter = QPainter(self.viewport())
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setBrush(QColor(123, 184, 234))
        painter.setPen(QPen(Qt.white, 0.5))

        scale_text = f'{self._cur_scale * 100:.0f}%'
        scale_text_bounding_rect = self._scale_font_metrics.boundingRect(
            scale_text)
        viewport_rect = self.viewport().rect()
        # Align the scale text to (Qt.AlignHCenter | Qt.AlignBottom)
        pad = 2
        self._scale_text_rect = QRect(viewport_rect.width() / 2 - scale_text_bounding_rect.width() / 2,
                                      viewport_rect.height() - scale_text_bounding_rect.height() - 6,
                                      scale_text_bounding_rect.width(), scale_text_bounding_rect.height())\
            .adjusted(-pad, -pad, pad, pad)  # add pads to update when scrolling without artifacts

        # Use QPainterPath to draw text with outline
        path = QPainterPath()
        path.addText(self._scale_text_rect.bottomLeft(), self._scale_font,
                     scale_text)
        painter.drawPath(path)
Exemplo n.º 9
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.save()
        path = QPainterPath()

        painter.setFont(self.font)
        painter.setRenderHint(QPainter.Antialiasing)

        pen = QPen(QColor(0, 0, 0, 230))
        pen_width = 3
        pen.setWidth(pen_width)

        len = self.metrics.width(self.txt)
        w = self.width()
        px = (len - w) / 2
        if px < 0:
            px = -px
        py = (self.height() - self.metrics.height()) / 2 + self.metrics.ascent()
        if py < 0:
            py = -py

        path.addText(px + 2, py + 2, self.font, self.txt)
        painter.strokePath(path, pen)
        painter.drawPath(path)
        painter.fillPath(path, QBrush(self.color))
        painter.restore()
Exemplo n.º 10
0
 def paintEvent(self, event):
     kist = QPen()
     kist.setColor(QColor('Yellow'))
     kist.setWidth(2)
     kist.setJoinStyle(Qt.RoundJoin)
     painter = QPainter(self)
     painter.setPen(kist)
     painter.drawPath(self.path)
Exemplo n.º 11
0
    def paintEngine(self):
        myGradient = QLinearGradient()
        myPen = QPen()
        myPolygon = QPolygonF()

        myPath = QPainterPath()
        myPath.addPolygon(myPolygon)

        painter = QPainter()
        painter.setBrush(myGradient)
        painter.setPen(myPen)
        painter.drawPath(myPath)
Exemplo n.º 12
0
    def __init__(self,
                 name,
                 baseSize,
                 contourPath,
                 presetFilename=None,
                 image=None):
        """

        @param name:
        @type name: str
        @param baseSize:
        @type baseSize: int
        @param contourPath: base shape of the brush family
        @type contourPath: QPainterPath
        @param presetFilename: preset file
        @type presetFilename: str
        """
        self.name = name
        self.baseSize = baseSize
        # init the brush pixmap
        self.basePixmap = QPixmap(self.baseSize, self.baseSize)
        # to get an alpha channel, we must fill the pixmap a first time with an opacity < 255
        self.basePixmap.fill(QColor(0, 0, 0, 0))
        if self.name == 'eraser':
            self.basePixmap.fill(QColor(0, 0, 0, 255))
        self.contourPath = contourPath
        # init brush cursor
        self.baseCursor = QPixmap(self.baseSize, self.baseSize)
        self.baseCursor.fill(QColor(0, 0, 0, 0))
        qp = QPainter(self.baseCursor)
        pen = qp.pen()
        pen.setWidth(self.baseSize / 20)
        qp.setPen(pen)  # needed!!
        qp.drawPath(contourPath)
        qp.end()
        self.__pxmp = None
        self.bOpacity = 1.0
        self.bFlow = 1.0
        self.bHardness = 1.0
        self.preset = None
        if presetFilename is not None:
            img = QImage(presetFilename)
        elif image is not None:
            img = image
        else:
            return
        img = img.convertToFormat(QImage.Format_ARGB32)
        buf = QImageBuffer(img)
        b = np.sum(buf[..., :3], axis=-1, dtype=np.float)
        b /= 3
        buf[..., 3] = b
        self.preset = QPixmap.fromImage(img)
Exemplo n.º 13
0
 def paint(self,
           painter: QtGui.QPainter,
           option: QtWidgets.QStyleOptionGraphicsItem,
           widget: T.Optional[QtWidgets.QWidget] = ...) -> None:
     path = self.outlinePath()
     painter.drawPath(path)
     arcPoints = self.cubicPointsForAngleInterval(self.startAngle,
                                                  self.endAngle)
     arcPoints = [i * self.maxRadius for i in arcPoints]
     painter.drawEllipse(arcPoints[0], 2, 2)
     painter.drawEllipse(arcPoints[1], 4, 4)
     painter.drawEllipse(arcPoints[2], 6, 6)
     painter.drawEllipse(arcPoints[3], 8, 8)
Exemplo n.º 14
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
Exemplo n.º 15
0
    def paintEvent(self, event):
        super(QtBubbleLabel, self).paintEvent(event)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)  # 抗锯齿

        rectPath = QPainterPath()  # 圆角矩形

        height = self.height() - 8  # 往上偏移8
        rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5)
        x = self.width() / 5 * 4
        # 边框画笔
        painter.setPen(
            QPen(self.BorderColor, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        # 背景画刷
        painter.setBrush(self.BackgroundColor)
        # 绘制形状
        painter.drawPath(rectPath)
Exemplo n.º 16
0
    def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem,
              index: QWidget) -> None:
        """
		Defines how the WireGraphics gets painted (color, width, etc.).
		:param painter: A QPainter
		:param option: A QStyleOptionGraphicsItem
		:param index: A QWidget
		:return: None
		"""
        path = self.buildPath()

        pen = QPen()
        pen.setWidth(WireGraphics.PEN_WIDTH)
        if self.isSelected():
            pen.setColor(WireGraphics.COLOR_ON_SELECTED)
        else:
            pen.setColor(WireGraphics.COLOR)

        painter.setPen(pen)
        painter.drawPath(path)
Exemplo n.º 17
0
    def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem,
              widget: Optional[QWidget]) -> None:

        # Draw a circle for the node
        pen = QPen(Qt.gray)
        pen.setWidth(2)
        pen.setCosmetic(True)

        # Combine ideas from these code samples to draw items at a fixed size:
        # https://stackoverflow.com/questions/1222914/qgraphicsview-and-qgraphicsitem-don%C2%B4t-scale-item-when-scaling-the-view-rect
        # https://www.qtcentre.org/threads/28691-Scale-independent-QGraphicsItem

        object_rect = self.boundingRect()
        mapped_rect = painter.transform().mapRect(object_rect)

        width_ratio = object_rect.width() / mapped_rect.width()

        scale_factor = max(1, width_ratio)

        painter.setPen(pen)
        painter.setBrush(Qt.gray)

        scaled_diameter = self.diameter * scale_factor

        painter.drawEllipse((self.x - scaled_diameter / 2),
                            (self.y - scaled_diameter / 2), scaled_diameter,
                            scaled_diameter)

        # Draw text for the node name
        label_path = QPainterPath()
        label_font = QFont("Calibri", 10 * scale_factor)
        label_path.addText(self.x, -self.y - self.diameter / 2, label_font,
                           self.name)
        painter.scale(1.0, -1.0)

        painter.setBrush(Qt.blue)
        painter.setPen(Qt.NoPen)
        painter.drawPath(label_path)
    def drawCursor(self, painter: QPainter = None) -> None:
        painter.save()
        painter.setPen(self.__cursorColor)

        text: str = "+"

        # 根据右侧的百分比显示字体大小
        textFont: QFont = QFont()
        size: int = int(20 + (35 * self.__percent / 100))
        textFont.setPixelSize(size)

        # 计算文字的宽度高度,自动移到鼠标按下处的中心点
        fm: QFontMetrics = QFontMetrics(textFont)
        textWidth: int = fm.width(text)
        textHeight: int = fm.height()
        textPoint: QPoint = self.__lastPos - QPoint(textWidth // 2,
                                                    -(textHeight // 4))

        path: QPainterPath = QPainterPath()
        path.addText(textPoint, textFont, text)
        painter.drawPath(path)

        painter.restore()
Exemplo n.º 19
0
    def paintEvent(self, event):

        super(CircularBrush, self).paintEvent(event)

        # draw brush
        if hasattr(self, 'brush_state') and self.brush_state.draw:
            painter = QPainter()
            shapes = self.create_brush_shape()
            for shape in shapes:
                shape = [QPointF(point[0], point[1]) for point in shape]

                path = QPainterPath()
                start_pos = shape.pop(0)
                path.moveTo(start_pos)
                [path.lineTo(point) for point in shape]

                painter.setRenderHint(painter.Antialiasing)
                #  painter.setRenderHint(painter.HighQualityAnti)
                painter.begin(self)

                painter.setPen(QPen(Qt.red, 1))
                painter.drawPath(path)

            painter.end()
Exemplo n.º 20
0
    def paintPagesView(self):
        # This method paints the page layout, nothing more
        # It also paints the background at page breaks
        # The design is drawn only when the editor is in page mode.
        if (self.m_usePageMode):
            # Draw page breaks
            pageWidth = self.m_pageMetrics.pxPageSize().width()
            pageHeight = self.m_pageMetrics.pxPageSize().height()

            p = QPainter(self.viewport())
            borderPen = QPen(self.palette().dark(), 1)

            curHeight = pageHeight - (self.verticalScrollBar().value() %
                                      pageHeight)

            # Horizontal offset if there is a scroll bar
            horizontalDelta = self.horizontalScrollBar().value()

            # Paint page views while there are remotely more visible pages
            while (curHeight < pageHeight + self.height()):

                p.setRenderHint(QPainter.Antialiasing)
                path = QPainterPath()
                # In painting page, height of the rect is (pageHeight - 10)
                # to give page break
                pageLayout = QRectF(0 - horizontalDelta,
                                    curHeight - pageHeight, pageWidth,
                                    pageHeight - 10)
                path.addRect(pageLayout)
                p.fillPath(path, Qt.white)

                p.setPen(borderPen)
                p.drawPath(path)

                # Go to next page
                curHeight += pageHeight
Exemplo n.º 21
0
    def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem,
              widget: QWidget) -> None:
        """
		Paints a port. This function is used implicitly by the QGraphicsView to render a port.
		
		:param painter: The painter to paint with.
		:type painter: QPainter
		:param option: provides style options for the item.
		:type option: QStyleOptionGraphicsItem
		:param widget: QWidget
		:type widget: It points to the widget that is being painted on; or make it = None.
		:return: None
		:rtype: NoneType
		"""

        pen = QPen(PortGraphics.PEN_COLOR)
        pen.setWidth(self.borderWidth)
        painter.setPen(pen)

        if type(self._port.getAction()) == ActionWrapper:
            painter.setBrush(PortGraphics.INNER_COLOR)
        else:
            painter.setBrush(PortGraphics.OUTER_COLOR)
        painter.drawPath(self.shape())
Exemplo n.º 22
0
    def drawBg(self, painter: QPainter) -> None:
        painter.save()
        painter.setPen(Qt.NoPen)

        bgColor: QColor = self.__bgColorOn if self.__checked else self.__bgColorOff
        if not self.isEnabled():
            bgColor.setAlpha(60)

        painter.setBrush(bgColor)

        if self.__buttonStyle is SwitchButton.ButtonStyle.ButtonStyle_Rect:
            painter.drawRoundedRect(self.rect(), self.__rectRadius, self.__rectRadius)
        elif self.__buttonStyle is SwitchButton.ButtonStyle.ButtonStyle_CircleIn:
            rect: QRect = QRect(0, 0, self.width(), self.height())
            side: int = min(rect.width(), rect.height())  # 半径为高度的一半

            # 左侧圆
            path1: QPainterPath = QPainterPath()
            path1.addEllipse(rect.x(), rect.y(), side, side)
            # 右侧圆
            path2: QPainterPath = QPainterPath()
            path2.addEllipse(rect.width() - side, rect.y(), side, side)
            # 中间矩形
            path3: QPainterPath = QPainterPath()
            path3.addRect(rect.x() + side // 2, rect.y(), rect.width() - side, rect.height())

            path: QPainterPath = QPainterPath()
            path = path3 + path1 + path2
            painter.drawPath(path)
        elif self.__buttonStyle is SwitchButton.ButtonStyle.ButtonStyle_CircleOut:
            rect: QRect = QRect(self.height() // 2,
                                self.__space,
                                self.width() - self.height(),
                                self.height() - self.__space * 2)
            painter.drawRoundedRect(rect, self.__rectRadius, self.__rectRadius)

        if self.__buttonStyle is SwitchButton.ButtonStyle.ButtonStyle_Rect or \
                self.__buttonStyle is SwitchButton.ButtonStyle.ButtonStyle_CircleIn:
            # 绘制文本和小圆,互斥
            if self.__showText:
                sliderWidth: int = min(self.width(), self.height()) - self.__space * 2
                if self.__buttonStyle is SwitchButton.ButtonStyle.ButtonStyle_Rect:
                    sliderWidth = self.width() // 2 - 5
                elif self.__buttonStyle is SwitchButton.ButtonStyle.ButtonStyle_CircleIn:
                    sliderWidth -= 5

                if self.__checked:
                    textRect: QRect = QRect(0, 0, self.width() - sliderWidth, self.height())
                    painter.setPen(self.__textColorOn)
                    painter.drawText(textRect, Qt.AlignCenter, self.__textOn)
                else:
                    textRect: QRect = QRect(sliderWidth, 0, self.width() - sliderWidth, self.height())
                    painter.setPen(self.__textColorOff)
                    painter.drawText(textRect, Qt.AlignCenter, self.__textOff)
            elif self.__showCircle:
                side: int = min(self.width(), self.height()) // 2
                y: int = (self.height() - side) // 2

                if self.__checked:
                    circleRect: QRect = QRect(side // 2, y, side, side)
                    pen: QPen = QPen(self.__textColorOn, 2)
                    painter.setPen(pen)
                    painter.setBrush(Qt.NoBrush)
                    painter.drawEllipse(circleRect)
                else:
                    circleRect: QRect = QRect(int(self.width() - (side * 1.5)), y, side, side)
                    pen: QPen = QPen(self.__textColorOff, 2)
                    painter.setPen(pen)
                    painter.setBrush(Qt.NoBrush)
                    painter.drawEllipse(circleRect)

        painter.restore()
Exemplo n.º 23
0
    def paint(self, painter: QPainter, option, widget=...) -> None:
        if self._source_pos is None or self._target_pos is None:
            return

        painter.setPen(self._pen)
        painter.drawPath(self._path)
Exemplo n.º 24
0
    def paintEvent(self, event):
        p = QPainter()
        p.begin(self)
        self._normalMap.render(p, event.rect())
        p.setPen(Qt.black)
        # p.drawText(self.rect(), Qt.AlignBottom | Qt.TextWordWrap, "Map data CCBYSA 2009 OpenStreetMap.org contributors")
        p.end()

        if self.zoomed:
            dim = min(self.width(), self.height())
            magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3)
            radius = magnifierSize / 2
            ring = radius - 15
            box = QSize(magnifierSize, magnifierSize)

            # reupdate our mask
            if self.maskPixmap.size() != box:
                self.maskPixmap = QPixmap(box)
                self.maskPixmap.fill(Qt.transparent)
                g = QRadialGradient()
                g.setCenter(radius, radius)
                g.setFocalPoint(radius, radius)
                g.setRadius(radius)
                g.setColorAt(1.0, QColor(255, 255, 255, 0))
                g.setColorAt(0.5, QColor(128, 128, 128, 255))
                mask = QPainter(self.maskPixmap)
                mask.setRenderHint(QPainter.Antialiasing)
                mask.setCompositionMode(QPainter.CompositionMode_Source)
                mask.setBrush(g)
                mask.setPen(Qt.NoPen)
                mask.drawRect(self.maskPixmap.rect())
                mask.setBrush(QColor(Qt.transparent))
                mask.drawEllipse(g.center(), ring, ring)
                mask.end()

            center = self.dragPos - QPoint(0, radius)
            center += QPoint(0, radius / 2)
            corner = center - QPoint(radius, radius)
            xy = center * 2 - QPoint(radius, radius)
            # only set the dimension to the magnified portion
            if self.zoomPixmap.size() != box:
                self.zoomPixmap = QPixmap(box)
                self.zoomPixmap.fill(Qt.lightGray)

            if True:
                p = QPainter(self.zoomPixmap)
                p.translate(-xy)
                self._largeMap.render(p, QRect(xy, box))
                p.end()

            clipPath = QPainterPath()
            clipPath.addEllipse(QPointF(center), ring, ring)
            p = QPainter(self)
            p.setRenderHint(QPainter.Antialiasing)
            p.setClipPath(clipPath)
            p.drawPixmap(corner, self.zoomPixmap)
            p.setClipping(False)
            p.drawPixmap(corner, self.maskPixmap)
            p.setPen(Qt.gray)
            p.drawPath(clipPath)

        if self.invert:
            p = QPainter(self)
            p.setCompositionMode(QPainter.CompositionMode_Difference)
            p.fillRect(event.rect(), Qt.white)
            p.end()
Exemplo n.º 25
0
    starPath.moveTo(28, 15)

    for i in range(5):
        starPath.lineTo(14 + 14 * math.cos(0.8 * i * math.pi),
                        15 + 14 * math.sin(0.8 * i * math.pi))

    starPath.closeSubpath()

    star = QImage(30, 30, QImage.Format_ARGB32)
    star.fill(Qt.transparent)
    painter = QPainter(star)
    painter.setRenderHint(QPainter.Antialiasing)
    painter.setPen(QColor.fromRgb(0xf6, 0xa6, 0x25))
    painter.setBrush(painter.pen().color())
    painter.drawPath(starPath)

    series2.setBrush(star)
    series2.setPen(QColor(Qt.transparent))

    chartView = QtCharts.QChartView(chart)

    chartView.setRenderHint(QPainter.Antialiasing)
    chart.addSeries(series0)
    chart.addSeries(series1)
    chart.addSeries(series2)

    chart.setTitle("Simple scatterchart example")
    chart.createDefaultAxes()
    chart.setDropShadowEnabled(False)
    chart.legend().setMarkerShape(QtCharts.QLegend.MarkerShapeFromSeries)
Exemplo n.º 26
0
    def paint(self,
              painter: QPainter,
              option: QStyleOptionGraphicsItem,
              widget: QWidget = ...):
        fillColor = self.color.darker(
            150) if option.state & QStyle.State_Selected else self.color
        if option.state & QStyle.State_MouseOver:
            fillColor = fillColor.lighter(125)

        lod = option.levelOfDetailFromTransform(painter.worldTransform())

        if lod < 0.2:
            if lod < 0.125:
                painter.fillRect(QRectF(0, 0, 110, 70), fillColor)
                return

            b = painter.brush()
            painter.setBrush(fillColor)
            painter.drawRect(13, 13, 97, 57)
            painter.setBrush(b)
            return

        oldPen = painter.pen()
        pen = oldPen
        width = 0
        if option.state & QStyle.State_Selected:
            width += 2
        pen.setWidth(width)
        b = painter.brush()
        painter.setBrush(
            QBrush(
                fillColor.darker(120 if option.state
                                 & QStyle.State_Sunken else 100)))

        painter.drawRect(QRect(14, 14, 79, 39))
        painter.setBrush(b)

        if lod >= 1:
            painter.setPen(QPen(Qt.gray, 1))
            painter.drawLine(15, 54, 94, 54)
            painter.drawLine(94, 53, 94, 15)
            painter.setPen(QPen(Qt.black, 0))

        # Draw text
        if lod >= 2:
            font = QFont("Times", 10)
            font.setStyleStrategy(QFont.ForceOutline)
            painter.setFont(font)
            painter.save()
            painter.scale(0.1, 0.1)
            painter.drawText(
                170, 180,
                f"Model: VSC-2000 (Very Small Chip) at {self.x}x{self.y}")
            painter.drawText(170, 200,
                             "Serial number: DLWR-WEER-123L-ZZ33-SDSJ")
            painter.drawText(170, 220, "Manufacturer: Chip Manufacturer")
            painter.restore()

        # Drawlines
        lines: List[QLineF] = []
        if lod >= 0.5:
            s = 1 if lod > 0.5 else 2
            for i in range(0, 11, s):
                lines.append(QLineF(18 + 7 * i, 13, 18 + 7 * i, 5))
                lines.append(QLineF(18 + 7 * i, 54, 18 + 7 * i, 62))

            for i in range(0, 7, s):
                lines.append(QLineF(5, 18 + i * 5, 13, 18 + i * 5))
                lines.append(QLineF(94, 18 + i * 5, 102, 18 + i * 5))

        if lod >= 0.4:
            lines.extend([
                QLineF(25, 35, 35, 35),
                QLineF(35, 30, 35, 40),
                QLineF(35, 30, 45, 35),
                QLineF(35, 40, 45, 35),
                QLineF(45, 30, 45, 40),
                QLineF(45, 35, 55, 35)
            ])
        painter.drawLines(lines[:])

        ## Draw red ink
        if len(self.stuff) > 1:
            p = painter.pen()
            painter.setPen(
                QPen(Qt.red, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
            painter.setBrush(Qt.NoBrush)
            path = QPainterPath()
            path.moveTo(self.stuff[0])
            for i in range(1, len(self.stuff)):
                path.lineTo(self.stuff[i])
            painter.drawPath(path)
            painter.setPen(p)
    def paint(self, painter: QPainter, option, widget):
        """
		Paints the contents of the visibilitybehavior. Override the parent paint function.
		Only renders the visibility behavior if the configuration variable, showBehaviors, is true.
		
		:param painter: Use a Qpainter object.
		:type painter: QPainter
		:param option: It provides style options for the item.
		:type option: QStyleOptionGraphicsItem
		:param widget: QWidget
		:type widget: It points to the widget that is being painted on; or make it = None.
		:return: None
		:rtype: NoneType
		"""
        # Only draw visibility behaviors if "Show Visibility Behaviors" action is checked in the View drop down.
        if sm.StateMachine.instance.configVars.showBehaviors:
            arrowColor = QColor(255, 200, 50)

            pen = QPen(arrowColor)
            if self.isSelected():
                pen.setStyle(Qt.DashDotLine)
                arrowColor = QColor(255, 0, 0)
            else:
                pen.setStyle(Qt.SolidLine)
                arrowColor = QColor(255, 200, 50)

            pen.setWidth(10)
            painter.setPen(pen)

            srcBR = self.scene().getGraphics(
                self._dataVB.getSrcComponent()).boundingRect(withMargins=False)
            dstBR = self.scene().getGraphics(
                self._dataVB.getDestComponent()).boundingRect(
                    withMargins=False)

            lengthSrcNodeSrcEdgeList = len(
                self._dataVB.getSrcComponent().getSrcVisibilityBehaviors())
            lengthDesNodeDesEdgeList = len(
                self._dataVB.getDestComponent().getDestVisibilityBehaviors())
            heightSrcNode = srcBR.height()
            heightDesNode = dstBR.height()
            widthDesNode = dstBR.width()
            # This is the index(+1 avoid 0 in calculation) of the edge at the SourceNode's edgeSrcList
            srcNodeIndex = self._dataVB.getSrcComponent(
            ).getSrcVisibilityBehaviors().index(self._dataVB) + 1
            # This is the index of the edge at the DesNode's _edgeDesList
            desNodeIndex = self._dataVB.getDestComponent(
            ).getDestVisibilityBehaviors().index(self._dataVB) + 1

            srcPos = self.scene().getGraphics(
                self._dataVB.getSrcComponent()).scenePos()
            dstPos = self.scene().getGraphics(
                self._dataVB.getDestComponent()).scenePos()

            # ComponentGraphics.MARGIN = 20
            x1 = srcPos.x(
            ) + 20  # x does not change, stay at the left most of the node
            y1 = srcPos.y() + (heightSrcNode /
                               (lengthSrcNodeSrcEdgeList + 1)) * srcNodeIndex
            x2 = dstPos.x() + widthDesNode + 20
            y2 = dstPos.y() + (heightDesNode /
                               (lengthDesNodeDesEdgeList + 1)) * desNodeIndex
            self._x1 = x1
            self._x2 = x2
            self._y1 = y1
            self._y2 = y2

            # build the path and arrowhead
            path, leftInTrue, pathBoundingRect = self.buildPath(x1, x2, y1, y2)
            arrowHead, arrowHeadBoundingRect = self.buildArrowHead(
                x1, x2, y1, y2, leftInTrue)

            brTLx = min(pathBoundingRect.topLeft().x(),
                        arrowHeadBoundingRect.topLeft().x())
            brTLy = min(pathBoundingRect.topLeft().y(),
                        arrowHeadBoundingRect.topLeft().y())
            brBLx = min(pathBoundingRect.bottomLeft().x(),
                        arrowHeadBoundingRect.bottomLeft().x())
            brBLy = max(pathBoundingRect.bottomLeft().y(),
                        arrowHeadBoundingRect.bottomLeft().y())
            brTRx = max(pathBoundingRect.topRight().x(),
                        arrowHeadBoundingRect.topRight().x())
            brHeight = brBLy - brTLy
            brWidth = brTRx - brTLx

            margin = 100

            self._boundingRect = QRectF(brTLx - margin, brTLy - margin,
                                        brWidth + margin * 2,
                                        brHeight + margin * 2)

            # Either of these lines will fix the drawing issue
            #self.prepareGeometryChange()
            self.scene().setSceneRect(self.scene().itemsBoundingRect())

            painter.drawPath(path)
            painter.drawPath(arrowHead)
            painter.fillPath(arrowHead, QBrush(arrowColor))