本文整理汇总了Python中PyQt4.QtGui.QGraphicsLineItem.line方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsLineItem.line方法的具体用法?Python QGraphicsLineItem.line怎么用?Python QGraphicsLineItem.line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QGraphicsLineItem
的用法示例。
在下文中一共展示了QGraphicsLineItem.line方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_controlpointline
# 需要导入模块: from PyQt4.QtGui import QGraphicsLineItem [as 别名]
# 或者: from PyQt4.QtGui.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: AxisItem
# 需要导入模块: from PyQt4.QtGui import QGraphicsLineItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsLineItem import line [as 别名]
class AxisItem(pg.GraphicsObject):
def __init__(self, parent=None, line=None, label=None, **kwargs):
super().__init__(parent, **kwargs)
self.setFlag(pg.GraphicsObject.ItemHasNoContents)
if line is None:
line = QLineF(0, 0, 1, 0)
self._spine = QGraphicsLineItem(line, self)
angle = QLineF(0, 0, 1, 0).angleTo(line)
angle = (180 - angle) % 360
dx = line.x2() - line.x1()
dy = line.y2() - line.y1()
rad = numpy.arctan2(dy, dx)
angle = (rad * 180 / numpy.pi) % 360
self._arrow = pg.ArrowItem(parent=self, angle=180 - angle)
self._arrow.setPos(self._spine.line().p2())
self._label = pg.TextItem(text=label, color=(10, 10, 10))
self._label.setParentItem(self)
self._label.setPos(self._spine.line().p2())
def setLabel(self, label):
if label != self._label:
self._label = label
self._label.setText(label)
def setPen(self, pen):
self._spine.setPen(pen)
def paint(self, painter, option, widget):
pass
def boundingRect(self):
return QRectF()
def viewTransformChanged(self):
self.__updateLabelPos()
def __updateLabelPos(self):
T = self.viewTransform()
if T is not None:
Tinv, ok = T.inverted()
else:
Tinv, ok = None, False
if not ok:
T = Tinv = QtGui.QTransform()
# map the axis spine to viewbox coord. system
viewbox_line = Tinv.map(self._spine.line())
angle = viewbox_line.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 = viewbox_line.pointAt(0.90)
if left_quad:
anchor = (0.5, -0.1)
else:
anchor = (0.5, 1.1)
pos = T.map(label_pos)
self._label.setPos(pos)
self._label.anchor = pg.Point(*anchor)
self._label.updateText()
self._label.setRotation(angle if left_quad else angle - 180)