當前位置: 首頁>>代碼示例>>Python>>正文


Python QGraphicsLineItem.line方法代碼示例

本文整理匯總了Python中AnyQt.QtWidgets.QGraphicsLineItem.line方法的典型用法代碼示例。如果您正苦於以下問題:Python QGraphicsLineItem.line方法的具體用法?Python QGraphicsLineItem.line怎麽用?Python QGraphicsLineItem.line使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AnyQt.QtWidgets.QGraphicsLineItem的用法示例。


在下文中一共展示了QGraphicsLineItem.line方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_controlpointline

# 需要導入模塊: from AnyQt.QtWidgets import QGraphicsLineItem [as 別名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import line [as 別名]
    def test_controlpointline(self):
        control = ControlPointLine()
        line = QGraphicsLineItem(10, 10, 200, 200)

        self.scene.addItem(line)
        self.scene.addItem(control)

        control.setLine(line.line())
        control.setFocus()
        control.lineChanged.connect(line.setLine)

        control.setLine(QLineF(30, 30, 180, 180))
        self.assertEqual(control.line(), line.line())
        self.assertEqual(line.line(), QLineF(30, 30, 180, 180))

        control.lineEdited.connect(line.setLine)

        self.view.show()
        self.app.exec_()

        self.assertEqual(control.line(), line.line())
開發者ID:PrimozGodec,項目名稱:orange3,代碼行數:23,代碼來源:test_controlpoints.py

示例2: AnchorItem

# 需要導入模塊: from AnyQt.QtWidgets import QGraphicsLineItem [as 別名]
# 或者: from AnyQt.QtWidgets.QGraphicsLineItem import line [as 別名]
class AnchorItem(pg.GraphicsObject):
    def __init__(self, parent=None, line=QLineF(), text="", **kwargs):
        super().__init__(parent, **kwargs)
        self._text = text
        self.setFlag(pg.GraphicsObject.ItemHasNoContents)

        self._spine = QGraphicsLineItem(line, self)
        angle = line.angle()

        self._arrow = pg.ArrowItem(parent=self, angle=0)
        self._arrow.setPos(self._spine.line().p2())
        self._arrow.setRotation(angle)
        self._arrow.setStyle(headLen=10)

        self._label = TextItem(text=text, color=(10, 10, 10))
        self._label.setParentItem(self)
        self._label.setPos(*self.get_xy())

        if parent is not None:
            self.setParentItem(parent)

    def get_xy(self):
        point = self._spine.line().p2()
        return point.x(), point.y()

    def setText(self, text):
        if text != self._text:
            self._text = text
            self._label.setText(text)
            self._label.setVisible(bool(text))

    def text(self):
        return self._text

    def setLine(self, *line):
        line = QLineF(*line)
        if line != self._spine.line():
            self._spine.setLine(line)
            self.__updateLayout()

    def line(self):
        return self._spine.line()

    def setPen(self, pen):
        self._spine.setPen(pen)

    def setArrowVisible(self, visible):
        self._arrow.setVisible(visible)

    def paint(self, painter, option, widget):
        pass

    def boundingRect(self):
        return QRectF()

    def viewTransformChanged(self):
        self.__updateLayout()

    def __updateLayout(self):
        T = self.sceneTransform()
        if T is None:
            T = QTransform()

        # map the axis spine to scene coord. system.
        viewbox_line = T.map(self._spine.line())
        angle = viewbox_line.angle()
        assert not np.isnan(angle)
        # note in Qt the y axis is inverted (90 degree angle 'points' down)
        left_quad = 270 < angle <= 360 or -0.0 <= angle < 90

        # position the text label along the viewbox_line
        label_pos = self._spine.line().pointAt(0.90)

        if left_quad:
            # Anchor the text under the axis spine
            anchor = (0.5, -0.1)
        else:
            # Anchor the text over the axis spine
            anchor = (0.5, 1.1)

        self._label.setPos(label_pos)
        self._label.setAnchor(pg.Point(*anchor))
        self._label.setRotation(-angle if left_quad else 180 - angle)

        self._arrow.setPos(self._spine.line().p2())
        self._arrow.setRotation(180 - angle)
開發者ID:PrimozGodec,項目名稱:orange3,代碼行數:88,代碼來源:plotutils.py


注:本文中的AnyQt.QtWidgets.QGraphicsLineItem.line方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。