python类QPainterPath()的实例源码

sheetview.py 文件源码 项目:pyree-old 作者: DrLuke 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def update(self, pos=None):
                path = QPainterPath()

                if pos is not None:
                    if self.ioend is None:
                        startpos = self.iostart.pos() + self.iostart.parent.pos()
                        endpos = pos
                    elif self.iostart is None:
                        startpos = pos
                        endpos = self.ioend.pos() + self.ioend.parent.pos()
                else:
                    startpos = self.iostart.pos() + self.iostart.parent.pos()
                    endpos = self.ioend.pos() + self.ioend.parent.pos()

                controlpoint = QPointF(abs((endpos - startpos).x()) * 0.8, 0)

                path.moveTo(startpos)
                path.cubicTo(startpos + controlpoint,
                             endpos - controlpoint,
                             endpos)

                self.setPath(path)
experiencebar.py 文件源码 项目:thegame 作者: afg984 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def paint(
            self,
            painter: QPainter,
            option: QStyleOptionGraphicsItem,
            widget: QWidget):
        pen = QPen()
        pen.setWidth(3)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setColor(QColor(61, 61, 61, 255))
        painter.setPen(pen)
        painter.setBrush(QBrush(QColor(61, 61, 61, 255), Qt.SolidPattern))
        painter.drawRect(
            QRectF(-self.maxWidth / 2, -10, self.maxWidth, 20))
        painter.setBrush(QBrush(QColor(240, 217, 108, 255), Qt.SolidPattern))
        painter.drawRect(
            QRectF(-self.maxWidth / 2, -10, self.displayWidth, 20))
        path = QPainterPath()

        path.addText(-self.maxWidth / 2, 35, QFont('monospace', 18, QFont.Bold), f'{self.name}  Lv.{self.level}  Exp. {self.actualExperience:{len(str(self.maxExperience))}}/{self.maxExperience}')

        # pen.setColor(Qt.white)
        pen.setWidth(2)
        painter.setPen(pen)
        painter.setBrush(QBrush(QColor(0, 0, 0, 61), Qt.SolidPattern))
        painter.drawPath(path)
message.py 文件源码 项目:thegame 作者: afg984 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def paint(
            self,
            painter: QPainter,
            option: QStyleOptionGraphicsItem,
            widget: QWidget):
        pen = QPen()
        pen.setWidth(1)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setColor(QColor(81, 81, 81, 255))
        painter.setPen(pen)
        painter.setBrush(QBrush(QColor(81, 81, 81, 255), Qt.SolidPattern))
        path = QPainterPath()
        path.addText(
            -self.width,
            self.height,
            QFont('monospace', 13, QFont.PreferNoHinting),
            self.text)
        painter.drawPath(path)
scoreboard.py 文件源码 项目:thegame 作者: afg984 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def paint(
            self,
            painter: QPainter,
            option: QStyleOptionGraphicsItem,
            widget: QWidget):
        pen = QPen()
        pen.setWidth(1)
        painter.setRenderHint(QPainter.Antialiasing)
        pen.setColor(QColor(81, 81, 81, 255))
        painter.setPen(pen)
        painter.setBrush(QBrush(QColor(81, 81, 81, 255), Qt.SolidPattern))
        for i, score in enumerate(self.scores):
            path = QPainterPath()
            path.addText(
                -self.width,
                14 + i * 16,
                QFont('monospace', 13, QFont.PreferNoHinting),
                f'{score.score:6}[{score.level:2}]  {score.hero_name}')
            painter.drawPath(path)
canvas2d.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def paint_shape(self, shape):
        """
        Create all plotting related parts of one shape.
        @param shape: The shape to be plotted.
        """
        start, start_ang = shape.get_start_end_points(True, True)
        shape.path = QPainterPath()
        shape.path.moveTo(start.x, -start.y)
        drawHorLine = lambda caller, start, end: shape.path.lineTo(end.x, -end.y)
        drawVerLine = lambda caller, start: None  # Not used in 2D mode
        shape.make_path(drawHorLine, drawVerLine)

        self.BB = self.BB.joinBB(shape.BB)

        shape.stmove = self.createstmove(shape)
        shape.starrow = self.createstarrow(shape)
        shape.enarrow = self.createenarrow(shape)
        shape.stmove.setParentItem(shape)
        shape.starrow.setParentItem(shape)
        shape.enarrow.setParentItem(shape)
routetext.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, text='S', startp=Point(x=0.0, y=0.0),):
        """
        Initialisation of the class.
        """
        QGraphicsItem.__init__(self)

        self.setFlag(QGraphicsItem.ItemIsSelectable, False)

        self.text = text
        self.sc = 1.0
        self.startp = QtCore.QPointF(startp.x, -startp.y)

        pencolor = QColor(0, 200, 255)
        self.brush = QColor(0, 100, 255)

        self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
        self.pen.setCosmetic(True)

        self.path = QPainterPath()
        self.path.addText(QtCore.QPointF(0, 0),
                          QFont("Arial", 10/self.sc),
                          self.text)
path_interface.py 文件源码 项目:brown 作者: ajyoon 项目源码 文件源码 阅读 83 收藏 0 点赞 0 评论 0
def __init__(self, brown_object, pos, pen, brush,
                 clip_start_x=None, clip_width=None):
        """
        Args:
            brown_object (Path): The path this interface belongs to
            pos (Point[GraphicUnit] or tuple): The position of the path root
                relative to the document.
            pen (PenInterface): The pen to draw outlines with.
            brush (BrushInterface): The brush to draw outlines with.
            clip_start_x (Unit or None): The local starting position for the
                path clipping region. Use `None` to render from the start.
            clip_width (Unit or None): The width of the path clipping region.
                Use `None` to render to the end
        """
        super().__init__(brown_object)
        self.qt_path = QtGui.QPainterPath()
        self.qt_object = QClippingPath(self.qt_path,
                                        clip_start_x, clip_width)
        self.pos = pos
        self.pen = pen
        self.brush = brush
        self.clip_start_x = clip_start_x
        self.clip_width = clip_width

    ######## PUBLIC PROPERTIES ########
qtPen.py 文件源码 项目:otRebuilder 作者: Pal3love 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, glyphSet, path=None):
        BasePen.__init__(self, glyphSet)
        if path is None:
            from PyQt5.QtGui import QPainterPath
            path = QPainterPath()
        self.path = path
connection.py 文件源码 项目:PyNoder 作者: johnroper100 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def paint(self, painter, option, widget):
        srcPoint = self.mapFromScene(self.__srcPortCircle.centerInSceneCoords())
        dstPoint = self.mapFromScene(self.__dstPortCircle.centerInSceneCoords())

        dist_between = dstPoint - srcPoint

        self.__path = QtGui.QPainterPath()
        self.__path.moveTo(srcPoint)
        self.__path.cubicTo(
            srcPoint + QtCore.QPointF(0, 0),
            dstPoint - QtCore.QPointF(0, 0),
            dstPoint
            )
        self.setPath(self.__path)
        super(Connection, self).paint(painter, option, widget)
canvas2d.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, shape):
        QGraphicsLineItem.__init__(self)
        StMove.__init__(self, shape)

        self.allwaysshow = False
        self.path = QPainterPath()

        self.setFlag(QGraphicsItem.ItemIsSelectable, False)

        self.pen = QPen(QColor(50, 100, 255), 1, QtCore.Qt.SolidLine,
                        QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
        self.pen.setCosmetic(True)
        self.make_papath()
canvas2d.py 文件源码 项目:dxf2gcode 作者: cnc-club 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def make_papath(self):
        """
        To be called if a Shape shall be printed to the canvas
        @param canvas: The canvas to be printed in
        @param pospro: The color of the shape
        """
        self.path = QPainterPath()
        if len(self.geos):
            start = self.geos.abs_el(0).get_start_end_points(True)
            self.path.moveTo(start.x, -start.y)
        drawHorLine = lambda caller, start, end: self.path.lineTo(end.x, -end.y)
        drawVerLine = lambda caller, start: None  # Not used in 2D mode
        self.make_path(drawHorLine, drawVerLine)
reversi_window.py 文件源码 项目:reversi_ai 作者: andysalerno 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def paintEvent(self, q_paint_event):
        # board background color
        painter = QtGui.QPainter(self)
        bg_path = QtGui.QPainterPath()
        bg_path.addRect(0, 0, self.width(), self.height())
        painter.fillPath(bg_path, GREEN)

        # draw the board lines
        for i in range(8):
            x_pos = self.width() / 8 * i
            painter.drawLine(x_pos, 0, x_pos, self.height())

            y_pos = self.height() / 8 * i
            painter.drawLine(0, y_pos, self.width(), y_pos)

        if self.board is not None and len(self.board) >= 8 * 8:
            for h in range(8):
                for w in range(8):
                    pieces_path = QtGui.QPainterPath()
                    w_dist = self.width() / 8
                    h_dist = self.height() / 8

                    x_pos = w_dist * w
                    y_pos = h_dist * h

                    bounding_rect = QtCore.QRectF(x_pos, y_pos, w_dist, h_dist)

                    index = (h * 8) + w
                    piece = self.board[index]
                    if piece == 'O':
                        pieces_path.addEllipse(bounding_rect)
                        painter.fillPath(pieces_path, WHITE)
                    elif piece == 'X':
                        pieces_path.addEllipse(bounding_rect)
                        painter.fillPath(pieces_path, BLACK)
gl_fallback.py 文件源码 项目:gpvdm 作者: roderickmackenzie 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def draw_photon(self,qp,start_x,start_y,up):
        wx=np.arange(0, 100.0 , 0.1)
        wy=np.sin(wx*3.14159*0.1)*15

        pen=QPen()
        pen.setWidth(2)

        if up==True:
            pen.setColor(QColor(0,0,255))
        else:
            pen.setColor(QColor(0,255,0))

        qp.setPen(pen)

        for i in range(1,len(wx)):
            qp.drawLine((int)(start_x-wy[i-1]),(int)(start_y+wx[i-1]),(int)(start_x-wy[i]),(int)(start_y+wx[i]))

        if up==True:
            path=QPainterPath()

            path.moveTo (start_x-10, start_y);
            path.lineTo (start_x-10, start_y);

            path.lineTo (start_x+10,   start_y);

            path.lineTo (start_x, start_y-20);

            qp.fillPath (path, QBrush (QColor (0,0,255)))
        else:
            path=QPainterPath()

            path.moveTo (start_x-10, start_y+100.0);
            path.lineTo (start_x-10, start_y+100.0);

            path.lineTo (start_x+10,   start_y+100.0);

            path.lineTo (start_x, start_y+100.0+20);

            qp.setPen (Qt.NoPen);
            qp.fillPath (path, QBrush (QColor (0,255,0)))
HandWriteRecognition.py 文件源码 项目:pyqt5 作者: yurisnm 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self):
        QGraphicsView.__init__(self)
        self.setScene(GraphicsScene())
        self.setSceneRect(QRectF(self.viewport().rect()))
        self.PIX = QPixmap()
        self.timer = QTimer()
        self.timer.timeout.connect(self.proccessImage)
        self.path = QPainterPath()
        self.item = GraphicsPathItem()
        self.scene().addItem(self.item)
HandWriteRecognition.py 文件源码 项目:pyqt5 作者: yurisnm 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def switch_to_text(self, text):

        font = QFont()
        font.setPointSize(self.__height_to_point(self.PIX.height()))
        graphics_text_item = QGraphicsTextItem(text)
        graphics_text_item.setFlag(QGraphicsItem.ItemIsMovable)
        graphics_text_item.setFont(font)
        self.scene().addItem(graphics_text_item)
        graphics_text_item.setPos(
            QPoint(self.item.boundingRect().x(), self.item.boundingRect().y()))
        self.path = QPainterPath()
        self.item = GraphicsPathItem()
        self.scene().addItem(self.item)
HandWriteRecognition.py 文件源码 项目:pyqt5 作者: yurisnm 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def clear(self):
        self.scene().clear()
        self.path = QPainterPath()
        self.item = GraphicsPathItem()
        self.item.setPath(self.path)
        self.scene().addItem(self.item)
SimpleFreeHand.py 文件源码 项目:pyqt5 作者: yurisnm 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self):
        super(GraphicsView, self).__init__()
        self.setScene(QGraphicsScene())
        self.path = QPainterPath()
        self.item = GraphicsPathItem()
        self.scene().addItem(self.item)
test_q_clipping_path.py 文件源码 项目:brown 作者: ajyoon 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_calculate_clipping_area_covering_full_path(self):
        painter_path = QtGui.QPainterPath()
        painter_path.lineTo(100, 200)
        expected_rect = painter_path.boundingRect()
        result_rect = QClippingPath.calculate_clipping_area(
            painter_path.boundingRect(), None, None, 0)
        assert(result_rect.x() == expected_rect.x())
        assert(result_rect.y() == expected_rect.y())
        assert(result_rect.width() == expected_rect.width())
        assert(result_rect.height() == expected_rect.height())
test_q_clipping_path.py 文件源码 项目:brown 作者: ajyoon 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_calculate_clipping_area_starting_in_path(self):
        painter_path = QtGui.QPainterPath()
        painter_path.lineTo(100, 200)
        result_rect = QClippingPath.calculate_clipping_area(
            painter_path.boundingRect(), 50, None, 0)
        assert(result_rect.x() == 50)
        assert(result_rect.y() == painter_path.boundingRect().y())
        assert(result_rect.width() == 50)
        assert(result_rect.height() == painter_path.boundingRect().height())
test_q_clipping_path.py 文件源码 项目:brown 作者: ajyoon 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_calculate_clipping_area_ending_in_path(self):
        painter_path = QtGui.QPainterPath()
        painter_path.lineTo(100, 200)
        result_rect = QClippingPath.calculate_clipping_area(
            painter_path.boundingRect(), None, 50, 0)
        assert(result_rect.x() == 0)
        assert(result_rect.y() == painter_path.boundingRect().y())
        assert(result_rect.width() == 50)
        assert(result_rect.height() == painter_path.boundingRect().height())
test_q_clipping_path.py 文件源码 项目:brown 作者: ajyoon 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_calculate_clipping_area_starting_and_ending_in_path(self):
        painter_path = QtGui.QPainterPath()
        painter_path.lineTo(100, 200)
        result_rect = QClippingPath.calculate_clipping_area(
            painter_path.boundingRect(), 25, 30, 0)
        assert(result_rect.x() == 25)
        assert(result_rect.y() == painter_path.boundingRect().y())
        assert(result_rect.width() == 30)
        assert(result_rect.height() == painter_path.boundingRect().height())
transformations.py 文件源码 项目:Mac-Python-3.X 作者: L1nwatch 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self, parent=None):
        super(RenderArea, self).__init__(parent)

        newFont = self.font()
        newFont.setPixelSize(12)
        self.setFont(newFont)

        fontMetrics = QFontMetrics(newFont)
        self.xBoundingRect = fontMetrics.boundingRect("x")
        self.yBoundingRect = fontMetrics.boundingRect("y")
        self.shape = QPainterPath()
        self.operations = []
polygonwidget.py 文件源码 项目:Mac-Python-3.X 作者: L1nwatch 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def createPath(self):

        self.path = QPainterPath()
        angle = 2*math.pi/self._sides
        self.path.moveTo(self._outerRadius, 0)
        for step in range(1, self._sides + 1):
            self.path.lineTo(
                self._innerRadius * math.cos((step - 0.5) * angle),
                self._innerRadius * math.sin((step - 0.5) * angle)
                )
            self.path.lineTo(
                self._outerRadius * math.cos(step * angle),
                self._outerRadius * math.sin(step * angle)
                )
        self.path.closeSubpath()
tooltips.py 文件源码 项目:Mac-Python-3.X 作者: L1nwatch 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self):    
        self.myPath = QPainterPath()
        self.myPosition = QPoint()
        self.myColor  = QColor()
        self.myToolTip = ''
transformations.py 文件源码 项目:examples 作者: pyqt 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, parent=None):
        super(RenderArea, self).__init__(parent)

        newFont = self.font()
        newFont.setPixelSize(12)
        self.setFont(newFont)

        fontMetrics = QFontMetrics(newFont)
        self.xBoundingRect = fontMetrics.boundingRect("x")
        self.yBoundingRect = fontMetrics.boundingRect("y")
        self.shape = QPainterPath()
        self.operations = []
polygonwidget.py 文件源码 项目:examples 作者: pyqt 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def createPath(self):

        self.path = QPainterPath()
        angle = 2*math.pi/self._sides
        self.path.moveTo(self._outerRadius, 0)
        for step in range(1, self._sides + 1):
            self.path.lineTo(
                self._innerRadius * math.cos((step - 0.5) * angle),
                self._innerRadius * math.sin((step - 0.5) * angle)
                )
            self.path.lineTo(
                self._outerRadius * math.cos(step * angle),
                self._outerRadius * math.sin(step * angle)
                )
        self.path.closeSubpath()
tooltips.py 文件源码 项目:examples 作者: pyqt 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self):    
        self.myPath = QPainterPath()
        self.myPosition = QPoint()
        self.myColor  = QColor()
        self.myToolTip = ''
graphs.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def shape(self):
        """Qt Function
        Return a more accurate shape for this item so that
        mouse hovering is more accurate"""
        path = QtGui.QPainterPath()
        path.addRect(QtCore.QRectF(-3, -1/2 * constantsAndConfigs.trackHeight, 9, constantsAndConfigs.trackHeight)) #this is directly related to inits parameter x, y, w, h
        return path
graphs.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def shape(self):
        """Return a more accurate shape for this item so that
        mouse hovering is more accurate"""
        path = QtGui.QPainterPath()
        path.addEllipse(QtCore.QRectF(-5, -5, 14, 14)) #this is directly related to inits parameter. -3, -3, 6, 6.
        return path
timeline.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def shape(self):
        """Return a more accurate shape for this item so that
        mouse hovering is more accurate"""
        path = QtGui.QPainterPath()
        path.addRect(QtCore.QRectF(-2, -2, 4, self.parentCCPath.rect().height() + 4 )) #this is directly related to inits parameter x, y, w, h
        return path


问题


面经


文章

微信
公众号

扫码关注公众号