本文整理汇总了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())
示例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)