本文整理汇总了Python中PyQt5.QtCore.QLineF.setP2方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.setP2方法的具体用法?Python QLineF.setP2怎么用?Python QLineF.setP2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.setP2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import setP2 [as 别名]
def mouseMoveEvent(self, event):
path, text = self._rulerObject
baseElem = path.elementAt(0)
canvasPos = event.localPos()
if event.modifiers() & Qt.ShiftModifier:
basePos = QPointF(baseElem.x, baseElem.y)
canvasPos = self.clampToOrigin(canvasPos, basePos)
canvasPos = self.magnetPos(canvasPos)
x, y = canvasPos.x(), canvasPos.y()
path.setElementPositionAt(1, x, baseElem.y)
path.setElementPositionAt(2, x, y)
path.setElementPositionAt(3, baseElem.x, baseElem.y)
line = QLineF(baseElem.x, baseElem.y, x, y)
l = line.length()
# angle() doesnt go by trigonometric direction. Weird.
# TODO: maybe split in positive/negative 180s (ff)
a = 360 - line.angle()
line.setP2(QPointF(x, baseElem.y))
h = line.length()
line.setP1(QPointF(x, y))
v = line.length()
text = "%d\n↔ %d\n↕ %d\nα %dº" % (l, h, v, a)
self._rulerObject = (path, text)
self.parent().update()