本文整理汇总了Python中PyQt4.QtCore.QLineF.setLength方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.setLength方法的具体用法?Python QLineF.setLength怎么用?Python QLineF.setLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.setLength方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_arrow
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import setLength [as 别名]
def draw_arrow(self, line, width, color):
(x1, y1), (x2, y2) = line
# compute points
line = QLineF(x1, y1, x2, y2)
# If the line is very small, we make our arrowhead smaller
arrowsize = min(14, line.length())
lineangle = radians(line.angle())
arrowpt1 = line.p2() + QPointF(sin(lineangle - (pi/3)) * arrowsize, cos(lineangle - (pi/3)) * arrowsize)
arrowpt2 = line.p2() + QPointF(sin(lineangle - pi + (pi/3)) * arrowsize, cos(lineangle - pi + (pi/3)) * arrowsize)
head = QPolygonF([line.p2(), arrowpt1, arrowpt2])
# We have to draw the actual line a little short for the tip of the arrowhead not to be too wide
adjustedLine = QLineF(line)
adjustedLine.setLength(line.length() - arrowsize/2)
# draw line
painter = self.current_painter
color = COLORS[color]
painter.save()
pen = QPen(painter.pen())
pen.setColor(color)
pen.setWidthF(width)
painter.setPen(pen)
painter.drawLine(adjustedLine)
# draw arrowhead
painter.setPen(Qt.NoPen)
brush = painter.brush()
brush.setColor(color)
brush.setStyle(Qt.SolidPattern)
painter.setBrush(brush)
painter.drawPolygon(head)
painter.restore()
示例2: start_end
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import setLength [as 别名]
def start_end(self):
line_start = QLineF(self)
line_end = QLineF(self.p2(), self.p1())
line_start.setLength(30)
line_end.setLength(30)
return line_start, line_end
示例3: paintArc
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import setLength [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 = QtGui.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(0.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)
示例4: dummyLine
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import setLength [as 别名]
def dummyLine(self, angle=None, length=None):
if angle is not None and length is not None:
pt1 = QLineF(QPointF(0.0, 0.0), QPointF(0.0, 1.0))
pt1.setAngle(angle)
pt1.setLength(length + 16)
self.__dummyLine = pt1
return
self.__dummyLine = QLineF()
示例5: arrow_path_concave
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import setLength [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
示例6: MyArrow
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import setLength [as 别名]
class MyArrow(QGraphicsLineItem):
def __init__(self):
super(MyArrow, self).__init__()
self.source = QPointF(0, 250)
self.dest = QPointF(120, 120)
self.line = QLineF(self.source, self.dest)
self.line.setLength(self.line.length() - 20)
def paint(self, QPainter, QStyleOptionGraphicsItem, QWidget_widget=None):
# setPen
pen = QPen()
pen.setWidth(5)
pen.setJoinStyle(Qt.MiterJoin) #让箭头变尖
QPainter.setPen(pen)
# draw line
QPainter.drawLine(self.line)
示例7: arrow_path_plain
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import setLength [as 别名]
def arrow_path_plain(line, width):
"""
Return an :class:`QPainterPath` of a plain 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))
path.moveTo(baseline.p1())
path.lineTo(baseline.p2())
stroker = QPainterPathStroker()
stroker.setWidth(width)
path = stroker.createStroke(path)
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(),
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
示例8: update
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import setLength [as 别名]
#.........这里部分代码省略.........
self.title_item.setRotation(-self.graph_line.angle())
c = self.title_item.mapToParent(self.title_item.boundingRect().center())
tl = self.title_item.mapToParent(self.title_item.boundingRect().topLeft())
self.title_item.setPos(title_pos - c + tl)
## Arrows
if not zoom_only:
if self.start_arrow_item:
self.scene().removeItem(self.start_arrow_item)
self.start_arrow_item = None
if self.end_arrow_item:
self.scene().removeItem(self.end_arrow_item)
self.end_arrow_item = None
if self.arrows & AxisStart:
if not zoom_only or not self.start_arrow_item:
self.start_arrow_item = QGraphicsPathItem(self.arrow_path, self)
self.start_arrow_item.setPos(self.graph_line.p1())
self.start_arrow_item.setRotation(-self.graph_line.angle() + 180)
self.start_arrow_item.setBrush(line_color)
self.start_arrow_item.setPen(line_color)
if self.arrows & AxisEnd:
if not zoom_only or not self.end_arrow_item:
self.end_arrow_item = QGraphicsPathItem(self.arrow_path, self)
self.end_arrow_item.setPos(self.graph_line.p2())
self.end_arrow_item.setRotation(-self.graph_line.angle())
self.end_arrow_item.setBrush(line_color)
self.end_arrow_item.setPen(line_color)
## Labels
n = len(self._ticks)
resize_plot_item_list(self.label_items, n, QGraphicsTextItem, self)
resize_plot_item_list(self.label_bg_items, n, QGraphicsRectItem, self)
resize_plot_item_list(self.tick_items, n, QGraphicsLineItem, self)
test_rect = QRectF(self.graph_line.p1(), self.graph_line.p2()).normalized()
test_rect.adjust(-1, -1, 1, 1)
n_v = self.graph_line.normalVector().unitVector()
if self.title_above:
n_p = n_v.p2() - n_v.p1()
else:
n_p = n_v.p1() - n_v.p2()
l_v = self.graph_line.unitVector()
l_p = l_v.p2() - l_v.p1()
for i in range(n):
pos, text, size, step = self._ticks[i]
hs = 0.5 * step
tick_pos = self.map_to_graph( pos )
if not test_rect.contains(tick_pos):
self.tick_items[i].setVisible(False)
self.label_items[i].setVisible(False)
continue
item = self.label_items[i]
item.setVisible(True)
if not zoom_only:
if self.id in XAxes or getattr(self, 'is_horizontal', False):
item.setHtml( '<center>' + Qt.escape(text.strip()) + '</center>')
else:
item.setHtml(Qt.escape(text.strip()))
item.setTextWidth(-1)
text_angle = 0
if dense_text:
w = min(item.boundingRect().width(), self.max_text_width)
item.setTextWidth(w)
if self.title_above:
label_pos = tick_pos + n_p * (w + self.text_margin) + l_p * item.boundingRect().height()/2
else:
label_pos = tick_pos + n_p * self.text_margin + l_p * item.boundingRect().height()/2
text_angle = -90 if self.title_above else 90
else:
w = min(item.boundingRect().width(), QLineF(self.map_to_graph(pos - hs), self.map_to_graph(pos + hs) ).length())
label_pos = tick_pos + n_p * self.text_margin - l_p * w/2
item.setTextWidth(w)
if not self.always_horizontal_text:
if self.title_above:
item.setRotation(-self.graph_line.angle() - text_angle)
else:
item.setRotation(self.graph_line.angle() - text_angle)
item.setPos(label_pos)
item.setDefaultTextColor(text_color)
self.label_bg_items[i].setRect(item.boundingRect())
self.label_bg_items[i].setPen(QPen(Qt.NoPen))
self.label_bg_items[i].setBrush(self.plot.color(OWPalette.Canvas))
item = self.tick_items[i]
item.setVisible(True)
tick_line = QLineF(v)
tick_line.translate(-tick_line.p1())
tick_line.setLength(size)
if self.title_above:
tick_line.setAngle(tick_line.angle() + 180)
item.setLine( tick_line )
item.setPen(line_color)
item.setPos(self.map_to_graph(pos))