当前位置: 首页>>代码示例>>Python>>正文


Python QtGui.QPainterPath类代码示例

本文整理汇总了Python中AnyQt.QtGui.QPainterPath的典型用法代码示例。如果您正苦于以下问题:Python QPainterPath类的具体用法?Python QPainterPath怎么用?Python QPainterPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QPainterPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __updateCurve

    def __updateCurve(self):
        self.prepareGeometryChange()
        self.__boundingRect = None
        if self.sourceAnchor and self.sinkAnchor:
            source_pos = self.sourceAnchor.anchorScenePos()
            sink_pos = self.sinkAnchor.anchorScenePos()
            source_pos = self.curveItem.mapFromScene(source_pos)
            sink_pos = self.curveItem.mapFromScene(sink_pos)

            # Adaptive offset for the curve control points to avoid a
            # cusp when the two points have the same y coordinate
            # and are close together
            delta = source_pos - sink_pos
            dist = math.sqrt(delta.x() ** 2 + delta.y() ** 2)
            cp_offset = min(dist / 2.0, 60.0)

            # TODO: make the curve tangent orthogonal to the anchors path.
            path = QPainterPath()
            path.moveTo(source_pos)
            path.cubicTo(source_pos + QPointF(cp_offset, 0),
                         sink_pos - QPointF(cp_offset, 0),
                         sink_pos)

            self.curveItem.setCurvePath(path)
            self.sourceIndicator.setPos(source_pos)
            self.sinkIndicator.setPos(sink_pos)
            self.__updateText()
        else:
            self.setHoverState(False)
            self.curveItem.setPath(QPainterPath())
开发者ID:PrimozGodec,项目名称:orange3,代码行数:30,代码来源:linkitem.py

示例2: test_shapeFromPath

    def test_shapeFromPath(self):
        path = QPainterPath()
        path.addRect(10, 10, 20, 20)

        pen = QPen(QColor("#FFF"), 2.0)
        path = shapeFromPath(path, pen)

        self.assertGreaterEqual(area(path.controlPointRect()),
                                (20 + 2.0) ** 2)
开发者ID:PrimozGodec,项目名称:orange3,代码行数:9,代码来源:test_graphicspathobject.py

示例3: move_label

 def move_label(label, frm, to):
     label.setX(to)
     to += t_box.width() / 2
     path = QPainterPath()
     path.lineTo(0, 4)
     path.lineTo(to - frm, 4)
     path.lineTo(to - frm, 8)
     p = QGraphicsPathItem(path)
     p.setPos(frm, 12)
     labels.addToGroup(p)
开发者ID:PrimozGodec,项目名称:orange3,代码行数:10,代码来源:owboxplot.py

示例4: setShapeRect

    def setShapeRect(self, rect):
        """
        Set the item's shape `rect`. The item should be confined within
        this rect.

        """
        path = QPainterPath()
        path.addEllipse(rect)
        self.setPath(path)
        self.__shapeRect = rect
开发者ID:RachitKansal,项目名称:orange3,代码行数:10,代码来源:nodeitem.py

示例5: test_graphicspathobject

    def test_graphicspathobject(self):
        obj = GraphicsPathObject()
        path = QPainterPath()
        obj.setFlag(GraphicsPathObject.ItemIsMovable)

        path.addEllipse(20, 20, 50, 50)

        obj.setPath(path)
        self.assertEqual(obj.path(), path)

        self.assertTrue(obj.path() is not path,
                        msg="setPath stores the path not a copy")

        brect = obj.boundingRect()
        self.assertTrue(brect.contains(path.boundingRect()))

        with self.assertRaises(TypeError):
            obj.setPath("This is not a path")

        brush = QBrush(QColor("#ffbb11"))
        obj.setBrush(brush)

        self.assertEqual(obj.brush(), brush)

        self.assertTrue(obj.brush() is not brush,
                        "setBrush stores the brush not a copy")

        pen = QPen(QColor("#FFFFFF"), 1.4)
        obj.setPen(pen)

        self.assertEqual(obj.pen(), pen)

        self.assertTrue(obj.pen() is not pen,
                        "setPen stores the pen not a copy")

        brect = obj.boundingRect()
        self.assertGreaterEqual(area(brect), (50 + 1.4 * 2) ** 2)

        self.assertIsInstance(obj.shape(), QPainterPath)

        positions = []
        obj.positionChanged[QPointF].connect(positions.append)

        pos = QPointF(10, 10)
        obj.setPos(pos)

        self.assertEqual(positions, [pos])

        self.scene.addItem(obj)
        self.view.show()

        self.app.exec_()
开发者ID:PrimozGodec,项目名称:orange3,代码行数:52,代码来源:test_graphicspathobject.py

示例6: test_layout

    def test_layout(self):
        file_desc, disc_desc, bayes_desc = self.widget_desc()
        file_item = NodeItem()
        file_item.setWidgetDescription(file_desc)
        file_item.setPos(0, 150)
        self.scene.add_node_item(file_item)

        bayes_item = NodeItem()
        bayes_item.setWidgetDescription(bayes_desc)
        bayes_item.setPos(200, 0)
        self.scene.add_node_item(bayes_item)

        disc_item = NodeItem()
        disc_item.setWidgetDescription(disc_desc)
        disc_item.setPos(200, 300)
        self.scene.add_node_item(disc_item)

        link = LinkItem()
        link.setSourceItem(file_item)
        link.setSinkItem(disc_item)
        self.scene.add_link_item(link)

        link = LinkItem()
        link.setSourceItem(file_item)
        link.setSinkItem(bayes_item)
        self.scene.add_link_item(link)

        layout = AnchorLayout()
        self.scene.addItem(layout)
        self.scene.set_anchor_layout(layout)

        layout.invalidateNode(file_item)
        layout.activate()

        p1, p2 = file_item.outputAnchorItem.anchorPositions()
        self.assertGreater(p1, p2)

        self.scene.node_item_position_changed.connect(layout.invalidateNode)

        path = QPainterPath()
        path.addEllipse(125, 0, 50, 300)

        def advance():
            t = time.clock()
            bayes_item.setPos(path.pointAtPercent(t % 1.0))
            disc_item.setPos(path.pointAtPercent((t + 0.5) % 1.0))

            self.singleShot(20, advance)

        advance()

        self.app.exec_()
开发者ID:PrimozGodec,项目名称:orange3,代码行数:52,代码来源:test_layout.py

示例7: test_layout

    def test_layout(self):
        one_desc, negate_desc, cons_desc = self.widget_desc()
        one_item = NodeItem()
        one_item.setWidgetDescription(one_desc)
        one_item.setPos(0, 150)
        self.scene.add_node_item(one_item)

        cons_item = NodeItem()
        cons_item.setWidgetDescription(cons_desc)
        cons_item.setPos(200, 0)
        self.scene.add_node_item(cons_item)

        negate_item = NodeItem()
        negate_item.setWidgetDescription(negate_desc)
        negate_item.setPos(200, 300)
        self.scene.add_node_item(negate_item)

        link = LinkItem()
        link.setSourceItem(one_item)
        link.setSinkItem(negate_item)
        self.scene.add_link_item(link)

        link = LinkItem()
        link.setSourceItem(one_item)
        link.setSinkItem(cons_item)
        self.scene.add_link_item(link)

        layout = AnchorLayout()
        self.scene.addItem(layout)
        self.scene.set_anchor_layout(layout)

        layout.invalidateNode(one_item)
        layout.activate()

        p1, p2 = one_item.outputAnchorItem.anchorPositions()
        self.assertTrue(p1 > p2)

        self.scene.node_item_position_changed.connect(layout.invalidateNode)

        path = QPainterPath()
        path.addEllipse(125, 0, 50, 300)

        def advance():
            t = time.process_time()
            cons_item.setPos(path.pointAtPercent(t % 1.0))
            negate_item.setPos(path.pointAtPercent((t + 0.5) % 1.0))

        timer = QTimer(negate_item, interval=20)
        timer.start()
        timer.timeout.connect(advance)
        self.app.exec_()
开发者ID:ales-erjavec,项目名称:orange-canvas,代码行数:51,代码来源:test_layout.py

示例8: ellipse_path

def ellipse_path(center, a, b, rotation=0):
    if not isinstance(center, QPointF):
        center = QPointF(*center)

    brect = QRectF(-a, -b, 2 * a, 2 * b)

    path = QPainterPath()
    path.addEllipse(brect)

    if rotation != 0:
        transform = QTransform().rotate(rotation)
        path = transform.map(path)

    path.translate(center)
    return path
开发者ID:ales-erjavec,项目名称:orange3,代码行数:15,代码来源:owvenndiagram.py

示例9: __init__

    def __init__(self, parent, *args):
        GraphicsPathObject.__init__(self, parent, *args)
        self.setAcceptHoverEvents(True)
        self.setPen(QPen(Qt.NoPen))
        self.normalBrush = QBrush(QColor("#CDD5D9"))
        self.connectedBrush = QBrush(QColor("#9CACB4"))
        self.setBrush(self.normalBrush)

        self.shadow = QGraphicsDropShadowEffect(
            blurRadius=10,
            color=QColor(SHADOW_COLOR),
            offset=QPointF(0, 0)
        )

        self.setGraphicsEffect(self.shadow)
        self.shadow.setEnabled(False)

        # Does this item have any anchored links.
        self.anchored = False

        if isinstance(parent, NodeItem):
            self.__parentNodeItem = parent
        else:
            self.__parentNodeItem = None

        self.__anchorPath = QPainterPath()
        self.__points = []
        self.__pointPositions = []

        self.__fullStroke = None
        self.__dottedStroke = None
        self.__shape = None
开发者ID:PrimozGodec,项目名称:orange3,代码行数:32,代码来源:nodeitem.py

示例10: __init__

    def __init__(self, parent=None, anchor=0, **kwargs):
        GraphicsPathObject.__init__(self, parent, **kwargs)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, False)
        self.setAcceptedMouseButtons(Qt.LeftButton)

        self.__constraint = 0
        self.__constraintFunc = None
        self.__anchor = 0
        self.__initialPosition = None
        self.setAnchor(anchor)

        path = QPainterPath()
        path.addEllipse(QRectF(-4, -4, 8, 8))
        self.setPath(path)

        self.setBrush(QBrush(Qt.lightGray, Qt.SolidPattern))
开发者ID:PrimozGodec,项目名称:orange3,代码行数:16,代码来源:controlpoints.py

示例11: setupGraphics

    def setupGraphics(self):
        """
        Set up the graphics.
        """
        shape_rect = QRectF(-24, -24, 48, 48)

        self.shapeItem = NodeBodyItem(self)
        self.shapeItem.setShapeRect(shape_rect)
        self.shapeItem.setAnimationEnabled(self.__animationEnabled)

        # Rect for widget's 'ears'.
        anchor_rect = QRectF(-31, -31, 62, 62)
        self.inputAnchorItem = SinkAnchorItem(self)
        input_path = QPainterPath()
        start_angle = 180 - self.ANCHOR_SPAN_ANGLE / 2
        input_path.arcMoveTo(anchor_rect, start_angle)
        input_path.arcTo(anchor_rect, start_angle, self.ANCHOR_SPAN_ANGLE)
        self.inputAnchorItem.setAnchorPath(input_path)

        self.outputAnchorItem = SourceAnchorItem(self)
        output_path = QPainterPath()
        start_angle = self.ANCHOR_SPAN_ANGLE / 2
        output_path.arcMoveTo(anchor_rect, start_angle)
        output_path.arcTo(anchor_rect, start_angle, - self.ANCHOR_SPAN_ANGLE)
        self.outputAnchorItem.setAnchorPath(output_path)

        self.inputAnchorItem.hide()
        self.outputAnchorItem.hide()

        # Title caption item
        self.captionTextItem = NameTextItem(self)

        self.captionTextItem.setPlainText("")
        self.captionTextItem.setPos(0, 33)

        def iconItem(standard_pixmap):
            item = GraphicsIconItem(self, icon=standard_icon(standard_pixmap),
                                    iconSize=QSize(16, 16))
            item.hide()
            return item

        self.errorItem = iconItem(QStyle.SP_MessageBoxCritical)
        self.warningItem = iconItem(QStyle.SP_MessageBoxWarning)
        self.infoItem = iconItem(QStyle.SP_MessageBoxInformation)

        self.prepareGeometryChange()
        self.__boundingRect = None
开发者ID:PrimozGodec,项目名称:orange3,代码行数:47,代码来源:nodeitem.py

示例12: __init__

    def __init__(self, parent=None, **kwargs):
        super().__init__(parent, **kwargs)
        self.setFlag(QGraphicsObject.ItemSendsGeometryChanges)

        self.__path = QPainterPath()
        self.__brush = QBrush(Qt.NoBrush)
        self.__pen = QPen()
        self.__boundingRect = None
开发者ID:ales-erjavec,项目名称:orange-canvas,代码行数:8,代码来源:graphicspathobject.py

示例13: redraw_path

 def redraw_path(self):
     self.path = QPainterPath()
     for segment in self.segment(self.data()):
         if self.fitted:
             self.draw_cubic_path(segment)
         else:
             self.draw_normal_path(segment)
     self._item.setPath(self.graph_transform().map(self.path))
     self._item.setPen(self.pen())
开发者ID:RachitKansal,项目名称:orange3,代码行数:9,代码来源:owparallelgraph.py

示例14: test_anchoritem

    def test_anchoritem(self):
        anchoritem = NodeAnchorItem(None)
        self.scene.addItem(anchoritem)

        path = QPainterPath()
        path.addEllipse(0, 0, 100, 100)

        anchoritem.setAnchorPath(path)

        anchor = AnchorPoint()
        anchoritem.addAnchor(anchor)

        ellipse1 = QGraphicsEllipseItem(-3, -3, 6, 6)
        ellipse2 = QGraphicsEllipseItem(-3, -3, 6, 6)
        self.scene.addItem(ellipse1)
        self.scene.addItem(ellipse2)

        anchor.scenePositionChanged.connect(ellipse1.setPos)

        with self.assertRaises(ValueError):
            anchoritem.addAnchor(anchor)

        anchor1 = AnchorPoint()
        anchoritem.addAnchor(anchor1)

        anchor1.scenePositionChanged.connect(ellipse2.setPos)

        self.assertSequenceEqual(anchoritem.anchorPoints(), [anchor, anchor1])

        self.assertSequenceEqual(anchoritem.anchorPositions(), [0.5, 0.5])
        anchoritem.setAnchorPositions([0.5, 0.0])

        self.assertSequenceEqual(anchoritem.anchorPositions(), [0.5, 0.0])

        def advance():
            t = anchoritem.anchorPositions()
            t = [(t + 0.05) % 1.0 for t in t]
            anchoritem.setAnchorPositions(t)

        timer = QTimer(anchoritem, interval=20)
        timer.start()
        timer.timeout.connect(advance)

        self.app.exec_()
开发者ID:ales-erjavec,项目名称:orange-canvas,代码行数:44,代码来源:test_nodeitem.py

示例15: updateSelectionRect

 def updateSelectionRect(self, event):
     pos = event.scenePos()
     buttonDownPos = event.buttonDownScenePos(Qt.LeftButton)
     rect = QRectF(pos, buttonDownPos).normalized()
     rect = rect.intersected(self.sceneRect())
     if not self.selectionRect:
         self.selectionRect = QGraphicsRectItem()
         self.selectionRect.setBrush(QColor(10, 10, 10, 20))
         self.selectionRect.setPen(QPen(QColor(200, 200, 200, 200)))
         self.addItem(self.selectionRect)
     self.selectionRect.setRect(rect)
     if event.modifiers() & Qt.ControlModifier or \
                     event.modifiers() & Qt.ShiftModifier:
         path = self.selectionArea()
     else:
         path = QPainterPath()
     path.addRect(rect)
     self.setSelectionArea(path)
     self.selectionRectPointChanged.emit(pos)
开发者ID:RachitKansal,项目名称:orange3,代码行数:19,代码来源:owimageviewer.py


注:本文中的AnyQt.QtGui.QPainterPath类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。