本文整理汇总了Python中AnyQt.QtGui.QPainterPath.quadTo方法的典型用法代码示例。如果您正苦于以下问题:Python QPainterPath.quadTo方法的具体用法?Python QPainterPath.quadTo怎么用?Python QPainterPath.quadTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtGui.QPainterPath
的用法示例。
在下文中一共展示了QPainterPath.quadTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintArc
# 需要导入模块: from AnyQt.QtGui import QPainterPath [as 别名]
# 或者: from AnyQt.QtGui.QPainterPath import quadTo [as 别名]
def paintArc(self, painter, option, widget):
assert self.source is self.dest
node = self.source
def best_angle():
"""...is the one furthest away from all other angles"""
angles = [QLineF(node.pos(), other.pos()).angle()
for other in chain((edge.source for edge in node.edges
if edge.dest == node and edge.source != node),
(edge.dest for edge in node.edges
if edge.dest != node and edge.source == node))]
angles.sort()
if not angles: # If this self-constraint is the only edge
return 225
deltas = np.array(angles[1:] + [360 + angles[0]]) - angles
return (angles[deltas.argmax()] + deltas.max()/2) % 360
angle = best_angle()
inf = QPointF(-1e20, -1e20) # Doesn't work with real -np.inf!
line0 = QLineF(node.pos(), inf)
line1 = QLineF(node.pos(), inf)
line2 = QLineF(node.pos(), inf)
line0.setAngle(angle)
line1.setAngle(angle - 13)
line2.setAngle(angle + 13)
p0 = shape_line_intersection(node.shape(), node.pos(), line0)
p1 = shape_line_intersection(node.shape(), node.pos(), line1)
p2 = shape_line_intersection(node.shape(), node.pos(), line2)
path = QPainterPath()
path.moveTo(p1)
line = QLineF(node.pos(), p0)
line.setLength(3*line.length())
pt = line.p2()
path.quadTo(pt, p2)
line = QLineF(node.pos(), pt)
self.setLine(line) # This invalidates DeviceCoordinateCache
painter.drawPath(path)
# Draw arrow head
line = QLineF(pt, p2)
self.arrowHead.clear()
for point in self._arrowhead_points(line):
self.arrowHead.append(point)
painter.setBrush(self.pen().color())
painter.drawPolygon(self.arrowHead)
# Update label position
self.label.setPos(path.pointAtPercent(.5))
if 90 < angle < 270: # Right-align the label
pos = self.label.pos()
x, y = pos.x(), pos.y()
self.label.setPos(x - self.label.boundingRect().width(), y)
self.squares.placeBelow(self.label)
示例2: arrow_path_concave
# 需要导入模块: from AnyQt.QtGui import QPainterPath [as 别名]
# 或者: from AnyQt.QtGui.QPainterPath import quadTo [as 别名]
def arrow_path_concave(line, width):
"""
Return a :class:`QPainterPath` of a pretty looking arrow.
"""
path = QPainterPath()
p1, p2 = line.p1(), line.p2()
if p1 == p2:
return path
baseline = QLineF(line)
# Require some minimum length.
baseline.setLength(max(line.length() - width * 3, width * 3))
start, end = baseline.p1(), baseline.p2()
mid = (start + end) / 2.0
normal = QLineF.fromPolar(1.0, baseline.angle() + 90).p2()
path.moveTo(start)
path.lineTo(start + (normal * width / 4.0))
path.quadTo(mid + (normal * width / 4.0),
end + (normal * width / 1.5))
path.lineTo(end - (normal * width / 1.5))
path.quadTo(mid - (normal * width / 4.0),
start - (normal * width / 4.0))
path.closeSubpath()
arrow_head_len = width * 4
arrow_head_angle = 50
line_angle = line.angle() - 180
angle_1 = line_angle - arrow_head_angle / 2.0
angle_2 = line_angle + arrow_head_angle / 2.0
points = [p2,
p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(),
baseline.p2(),
p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(),
p2]
poly = QPolygonF(points)
path_head = QPainterPath()
path_head.addPolygon(poly)
path = path.united(path_head)
return path