本文整理汇总了Python中PyQt4.QtCore.QLineF类的典型用法代码示例。如果您正苦于以下问题:Python QLineF类的具体用法?Python QLineF怎么用?Python QLineF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QLineF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
def paint(self, painter, option, widget=None):
painter.setPen(self.pen())
if not self.__arrowed:
headCenter = self.mapFromItem(self.__head[ENode.kGuiAttributeParent],
self.__head[ENode.kGuiAttributeParent].boundingRect().center())
tailCenter = self.mapFromItem(self.__tail[ENode.kGuiAttributeParent],
self.__tail[ENode.kGuiAttributeParent].boundingRect().center())
centerPoint = QLineF(headCenter, tailCenter).pointAt(0.5)
centerPoint.setX(self.__headOffsetLine.p2().x())
centerPoint.setX(self.__tailOffsetLine.p2().x())
painter.drawPath(self.drawPath(self.__headOffsetLine.p1(), self.__tailOffsetLine.p1())[0])
else:
painter.drawLine(self.__line)
painter.setPen(Qt.NoPen)
painter.setBrush(QColor(43, 43, 43))
headCutPoint = self.getIntersectPoint(self.__head[ENode.kGuiAttributeParent].Polygon,
self.__line.p1(), self.__line.p2())
tailCutPoint = self.getIntersectPoint(self.__tail[ENode.kGuiAttributeParent].Polygon,
self.__line.p2(), self.__line.p1())
painter.drawPolygon(self.getArrow(QLineF(headCutPoint, tailCutPoint)))
示例2: paint
def paint(self, painter, option, widget=None):
painter.setPen(EDraw.EColor.DefaultEnterHoverPen)
lineX = QLineF(QPointF(self.__gridSize, 0.0), QPointF(0.0, 0.0)).translated(-self.scenePos())
lineY = QLineF(QPointF(0.0, -self.__gridSize), QPointF(0.0, 0.0)).translated(-self.scenePos())
painter.drawLines([lineX, lineY])
self.__snapPoint = QPointF(self.__gridSize * round(self.scenePos().x() / self.__gridSize),
self.__gridSize * round(self.scenePos().y() / self.__gridSize))
if self.__isSnapMode:
painter.drawPolygon(self.__polygon.translated(self.__snapPoint - self.scenePos()))
self.__angle = 0.0
if self.__editPointOne is not None:
painter.drawPolygon(EDraw.Circle(20, 24).translated(-(self.scenePos()) + self.__BBTemp))
painter.drawLine(QLineF(QPointF(-(self.scenePos()) + self.__BBTemp), QPointF(0.0, 0.0)))
dummyLine = QLineF(QPointF(-(self.scenePos()) + self.__BBTemp), QPointF(0.0, 0.0))
painter.drawLine(QLineF(ETransform.rotatePoint(20, dummyLine.angle() + 180),
QPointF()).translated(-(self.scenePos()) + self.__BBTemp))
painter.drawLine(QLineF(ETransform.rotatePoint(20, dummyLine.angle() + 360),
QPointF()).translated(-(self.scenePos()) + self.__BBTemp))
self.__angle = dummyLine.angle()
painter.drawPolygon(self.__polygon)
painter.drawLine(self.__dummyLine)
示例3: setLine
def setLine(self, line):
"""
Set the arrow base line (a `QLineF` in object coordinates).
"""
if self.__line != line:
self.__line = line
# local item coordinate system
geom = self.geometry().translated(-self.pos())
if geom.isNull() and not line.isNull():
geom = QRectF(0, 0, 1, 1)
arrow_shape = arrow_path_concave(line, self.lineWidth())
arrow_rect = arrow_shape.boundingRect()
if not (geom.contains(arrow_rect)):
geom = geom.united(arrow_rect)
if self.__autoAdjustGeometry:
# Shrink the geometry if required.
geom = geom.intersected(arrow_rect)
# topLeft can move changing the local coordinates.
diff = geom.topLeft()
line = QLineF(line.p1() - diff, line.p2() - diff)
self.__arrowItem.setLine(line)
self.__line = line
# parent item coordinate system
geom.translate(self.pos())
self.setGeometry(geom)
示例4: plot_vert_line_graph
def plot_vert_line_graph(self, qp, x_line, color, c, arrow_up=False,
arrow_down=False):
if x_line < self._start_date or x_line > self._end_date:
return
x_line -= self._start_date
qp.save()
qp.setPen(color)
qp.setBrush(color)
qp.setRenderHint(QPainter.Antialiasing)
arrowSize = 2.0
x, y = self.origGraph(c)
line = QLineF(x + self.convX(x_line), y + 10, x + self.convX(x_line),
y + 50)
qp.drawLine(line)
if arrow_up:
arrowP1 = line.p1() + QPointF(arrowSize, arrowSize * 3)
arrowP2 = line.p1() + QPointF(-arrowSize, arrowSize * 3)
qp.drawLine(line.p1(), arrowP1)
qp.drawLine(line.p1(), arrowP2)
if arrow_down:
arrowP1 = line.p2() + QPointF(arrowSize, - arrowSize * 3)
arrowP2 = line.p2() + QPointF(-arrowSize, - arrowSize * 3)
qp.drawLine(line.p2(), arrowP1)
qp.drawLine(line.p2(), arrowP2)
qp.restore()
示例5: boundingRect
def boundingRect(self):
if self._line is None:
if self._orientation == Qt.Vertical:
self._line = QLineF(0, self._value, self._length, self._value)
else:
self._line = QLineF(self._value, 0, self._value, self._length)
r = QRectF(self._line.p1(), self._line.p2())
penw = self.pen().width()
return r.adjusted(-penw, -penw, penw, penw)
示例6: draw_arrow
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()
示例7: __activeControlMoved
def __activeControlMoved(self, pos):
line = QLineF(self.__line)
control = self.__activeControl
if control.anchor() == ControlPoint.TopLeft:
line.setP1(pos)
elif control.anchor() == ControlPoint.BottomRight:
line.setP2(pos)
if self.__line != line:
self.blockSignals(True)
self.setLine(line)
self.blockSignals(False)
self.lineEdited.emit(line)
示例8: update
def update(self):
QGraphicsObject.prepareGeometryChange(self)
self.__headPoint = self.mapFromItem(self.__head[ENode.kGuiAttributeParent],
self.__head[ENode.kGuiAttributePlug])
self.__tailPoint = self.mapFromItem(self.__tail[ENode.kGuiAttributeParent],
self.__tail[ENode.kGuiAttributePlug])
self.__headOffsetLine = QLineF(self.__headPoint, QPointF(self.__headPoint.x() + 15, self.__headPoint.y()))
self.__tailOffsetLine = QLineF(self.__tailPoint, QPointF(self.__tailPoint.x() - 15, self.__tailPoint.y()))
line = QLineF(self.__headPoint, self.__tailPoint)
self.__line = line
示例9: paint
def paint(self, painter):
pen = QPen(Qt.black)
pen.setWidthF(2.5)
painter.setPen(pen)
line = QLineF(self.startPoint, self.pos)
painter.drawLine(line)
if self.pos != self.startPoint:
#draw arrowhead
a = line.angle()
l1 = QLineF.fromPolar(25, a - 155)
l1.translate(self.pos)
l2 = QLineF.fromPolar(25, a + 155)
l2.translate(self.pos)
painter.drawLine(l1)
painter.drawLine(l2)
示例10: getPoints
def getPoints(self, count, opposite=False):
result = []
line = QLineF(self.__polygon.boundingRect().topLeft(), self.__polygon.boundingRect().topRight())
if opposite:
line = QLineF(self.__polygon.boundingRect().bottomLeft(), self.__polygon.boundingRect().bottomRight())
step = 1.0 / (count + 1)
currentStep = step
for x in range(0, count):
result.append(line.pointAt(currentStep))
currentStep += step
return result
示例11: paint
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' ) )
示例12: arrow_path_concave
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
示例13: MyArrow
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)
示例14: getIntersectPoint
def getIntersectPoint(self, polygon, point1, point2):
p1 = polygon[0] + point1
intersectPoint = QPointF()
for i in polygon:
p2 = i + point2
polyLine = QLineF(p1, p2)
intersectType = polyLine.intersect(QLineF(point1, point2), intersectPoint)
if intersectType == QLineF.BoundedIntersection:
break
p1 = p2
return intersectPoint
示例15: _updateTextAnchors
def _updateTextAnchors(self):
n = len(self._items)
items = self._items
dist = 15
shape = reduce(QPainterPath.united, [item.path() for item in items])
brect = shape.boundingRect()
bradius = max(brect.width() / 2, brect.height() / 2)
center = self.boundingRect().center()
anchors = _category_anchors(items)
self._textanchors = []
for angle, anchor_h, anchor_v in anchors:
line = QLineF.fromPolar(bradius, angle)
ext = QLineF.fromPolar(dist, angle)
line = QLineF(line.p1(), line.p2() + ext.p2())
line = line.translated(center)
anchor_pos = line.p2()
self._textanchors.append((anchor_pos, anchor_h, anchor_v))
for i in range(n):
self._updateTextItemPos(i)