本文整理汇总了Python中PyQt4.QtCore.QLineF.length方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.length方法的具体用法?Python QLineF.length怎么用?Python QLineF.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.length方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_arrow
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import length [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: paintArc
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import length [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)
示例3: overlay_for
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import length [as 别名]
def overlay_for(pt1, pt2, frequency):
# Construct the line-geometry, we'll use this to construct the ellipsoid
line = QLineF(pt1, pt2)
# Determine the radius for the ellipsoid
radius = fresnel_radius(line.length(), frequency)
# Draw the ellipsoid
zone = QPainterPath()
zone.addEllipse(QPointF(0., 0.), line.length() / 2, radius)
# Rotate the ellipsoid - same angle as the line
transform = QTransform()
transform.rotate(-line.angle())
zone = transform.map(zone)
# Center the zone over the line
lc = QRectF(pt1, pt2).center()
zc = zone.boundingRect().center()
zone.translate(lc.x() - zc.x(), lc.y() - zc.y())
return line, zone
示例4: MyArrow
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import length [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)
示例5: Line
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import length [as 别名]
class Line( QGraphicsLineItem ):
"""Defines a line by two points. If points are moved, line follows these movements."""
def __init__( self, startPoint, endPoint, ccs, paintToBorder = False, showIncline = False, color = 'orange', minLength = 0 ):
super( Line, self ).__init__( ccs )
self.startPoint = startPoint
self.endPoint = endPoint
self.ccs = ccs
self.paintToBorder = paintToBorder
self.showIncline = showIncline
self.color = color
self.visible = True
# by default we only want to draw lines if its two
# defining points are not too close together
self.drawAlways = False
self.minLength = minLength # pixel
# grmbl. Line was designed to be defined by two Point.Points. Now I want to be able to define
# lines as well from QPointFs.
try:
self.Rect = QRectF( self.startPoint.x, self.startPoint.y, self.endPoint.x, self.endPoint.y )
except:
self.Rect = QRectF( self.startPoint.x(), self.startPoint.y(), self.endPoint.x(), self.endPoint.y() )
def boundingRect( self ):
return self.Rect
def paint( self, painter, option, widget=None ):
if self.visible == True:
painter.setPen( QColor( self.color ) )
# see try-catch (pardon me) above
try:
self.sp = CST.toCcsCoord( self.ccs, self.startPoint.x, self.startPoint.y )
self.ep = CST.toCcsCoord( self.ccs, self.endPoint.x, self.endPoint.y )
except:
self.sp = CST.toCcsCoord( self.ccs, self.startPoint.x(), self.startPoint.y() )
self.ep = CST.toCcsCoord( self.ccs, self.endPoint.x(), self.endPoint.y() )
self.Rect = QRectF( self.sp, self.ep )
self.line = QLineF( self.sp, self.ep )
if self.line.length() > self.minLength or self.drawAlways == True:
painter.drawLine( self.line )
if self.paintToBorder == True:
# paint line to approximately the edge of the ccs.
ep2 = self.line.pointAt( self.ccs.width / self.line.length() * 2)
painter.drawLine(self.ep,ep2)
sp2 = self.line.pointAt(-self.ccs.width / self.line.length() * 2)
painter.drawLine(self.sp,sp2)
if self.showIncline == True:
incline = ( self.endPoint.y - self.startPoint.y ) / ( self.endPoint.x - self.startPoint.x )
# print text limited to 2 decimal digits.
painter.setBackground ( QBrush ( QColor( 'lightGrey' ) ) )
painter.setBackgroundMode (Qt.BGMode(1))
painter.setPen( QColor( 'black' ) )
#~ painter.drawText( self.ep.x() + 10, self.ep.y() + 10, QString ( '%.2f' %(incline) ) )
def setVisible( self, value ):
self.visible = value
def setPosition( self, startPoint, endPoint ):
self.startPoint = startPoint
self.endPoint = endPoint
def updateYourself( self, xDelta, yDelta ):
# There is no action needed, as a line gets its information
# from startPoint and endPoint
# Just adjust self.Rect to avoid case where line disappears mysteriously and after then,
# paint() is never called again
self.Rect = QRectF( self.startPoint.x, self.startPoint.y, self.endPoint.x, self.endPoint.y )