本文整理汇总了Python中PySide.QtGui.QPainterPath.cubicTo方法的典型用法代码示例。如果您正苦于以下问题:Python QPainterPath.cubicTo方法的具体用法?Python QPainterPath.cubicTo怎么用?Python QPainterPath.cubicTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainterPath
的用法示例。
在下文中一共展示了QPainterPath.cubicTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reshape
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import cubicTo [as 别名]
def reshape(self):
''' Update the shape of the edge (redefined function) '''
path = QPainterPath()
# If there is a starting point, draw a line to the first curve point
if self.start_point:
path.moveTo(self.source_connection.center)
path.lineTo(self.bezier[0])
else:
path.moveTo(self.source_connection.center)
# Loop over the curve points:
for group in self.bezier[1:]:
path.cubicTo(*[point.center for point in group])
# If there is an ending point, draw a line to it
if self.end_point:
path.lineTo(self.end_connection.center)
end_point = path.currentPosition()
arrowhead = self.angle_arrow(path)
path.lineTo(arrowhead[0])
path.moveTo(end_point)
path.lineTo(arrowhead[1])
path.moveTo(end_point)
try:
# Add the transition label, if any (none for the START edge)
font = QFont('arial', pointSize=8)
metrics = QFontMetrics(font)
label = self.edge.get('label', '') or ''
lines = label.split('\n')
width = metrics.width(max(lines)) # longest line
height = metrics.height() * len(lines)
# lp is the position of the center of the text
pos = self.mapFromScene(*self.edge['lp'])
if not self.text_label:
self.text_label = QGraphicsTextItem(
self.edge.get('label', ''), parent=self)
self.text_label.setX(pos.x() - width / 2)
self.text_label.setY(pos.y() - height / 2)
self.text_label.setFont(font)
# Make horizontal center alignment, as dot does
self.text_label.setTextWidth(
self.text_label.boundingRect().width())
fmt = QTextBlockFormat()
fmt.setAlignment(Qt.AlignHCenter)
cursor = self.text_label.textCursor()
cursor.select(QTextCursor.Document)
cursor.mergeBlockFormat(fmt)
cursor.clearSelection()
self.text_label.setTextCursor(cursor)
self.text_label.show()
except KeyError:
# no label
pass
self.setPath(path)
示例2: updatePath
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import cubicTo [as 别名]
def updatePath(self):
path = QPainterPath()
path.moveTo(self.pos1)
dx = self.pos2.x() - self.pos1.x()
dy = self.pos2.y() - self.pos1.y()
ctr1 = QPointF(self.pos1.x() + dx * 0.25, self.pos1.y() + dy * 0.1)
ctr2 = QPointF(self.pos1.x() + dx * 0.75, self.pos1.y() + dy * 0.9)
path.cubicTo(ctr1, ctr2, self.pos2)
self.setPath(path)
示例3: subPathList
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import cubicTo [as 别名]
def subPathList(self):
"""
TOWRITE
:rtype: QList<QPainterPath>
"""
s = self.scale() # qreal
trans = QTransform()
trans.rotate(self.rotation())
trans.scale(s, s)
## QList<QPainterPath> pathList;
pathList = []
path = self.objTextPath # QPainterPath
element = QPainterPath.Element
pathMoves = [] # QList<int>
numMoves = 0 # int
for i in range(0, path.elementCount()): # for(int i = 0; i < path.elementCount(); i++)
element = path.elementAt(i)
if element.isMoveTo():
pathMoves.append(i) # pathMoves << i;
numMoves += 1 # numMoves++;
pathMoves.append(path.elementCount()) # pathMoves << path.elementCount();
for p in range(0, len(pathMoves) - 1): # for(int p = 0; p < pathMoves.size()-1 && p < numMoves; p++)
if not (p < numMoves):
break
subPath = QPainterPath()
for i in range(pathMoves[p], pathMoves[p + 1]): # for(int i = pathMoves.value(p); i < pathMoves.value(p+1); i++)
element = path.elementAt(i)
if element.isMoveTo():
subPath.moveTo(element.x, element.y)
elif element.isLineTo():
subPath.lineTo(element.x, element.y)
elif element.isCurveTo():
subPath.cubicTo(path.elementAt(i).x, path.elementAt(i).y, # control point 1
path.elementAt(i + 1).x, path.elementAt(i + 1).y, # control point 2
path.elementAt(i + 2).x, path.elementAt(i + 2).y) # end point
pathList.append(trans.map(subPath))
return pathList
示例4: paint
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import cubicTo [as 别名]
def paint(self, painter, styleOption, widget):
''' Reimplemented to paint elements in alternating colors '''
path = self.path() # alias
pathEnd = None
i = 0
while True:
try:
element = path.elementAt(i)
# print type(element), element.type
if element.isMoveTo():
pathEnd = QPointF(element.x, element.y)
i+=1
elif element.isCurveTo():
# Gather curve data, since is spread across elements of type curveElementData
cp1 = QPointF(element.x, element.y)
element = path.elementAt(i+1)
cp2 = QPointF(element.x, element.y)
element = path.elementAt(i+2)
newEnd = QPointF(element.x, element.y)
# create a subpath, since painter has no drawCubic method
subpath=QPainterPath()
subpath.moveTo(pathEnd)
subpath.cubicTo(cp1, cp2, newEnd)
painter.drawPath(subpath)
pathEnd = newEnd
i+=3
else:
print "unhandled path element", element.type
i+=1
"""
TODO: if SegmentStringss contain lines (w/o Direction ControlPoints)
!!! We don't use QPathElements of type Line
elif element.isLineTo():
newEnd = QPointF(element.x, element.y)
painter.drawLine(pathEnd, newEnd)
pathEnd = newEnd
i+=1
"""
if i >= path.elementCount():
break
except Exception as inst:
print inst
break
# Alternate colors
if i%2 == 1:
painter.setPen(Qt.blue)
else:
painter.setPen(Qt.red)
示例5: draw_edge
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import cubicTo [as 别名]
def draw_edge(self, painter, option, edge, lane_offset):
from_y = 0.5 + lane_offset
to_y = 1 + from_y
pen = QPen(self.edge_color(edge.color), self.edge_thickness,
Qt.SolidLine, Qt.FlatCap, Qt.RoundJoin)
painter.setPen(pen)
if edge.from_lane == edge.to_lane:
line_x = edge.from_lane + 0.5
painter.drawLine(QPointF(line_x, from_y), QPointF(line_x, to_y))
else:
from_x = edge.from_lane + 0.5
to_x = edge.to_lane + 0.5
path = QPainterPath()
path.moveTo(QPointF(from_x, from_y))
path.cubicTo(from_x, from_y + 0.5, to_x, to_y - 0.5, to_x, to_y)
painter.drawPath(path)
示例6: reshape
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import cubicTo [as 别名]
def reshape(self):
''' Update the shape of the edge (redefined function) '''
path = QPainterPath()
# If there is a starting point, draw a line to the first curve point
if self.start_point:
path.moveTo(self.source_connection.center)
path.lineTo(self.bezier[0])
else:
path.moveTo(self.source_connection.center)
# Loop over the curve points:
for group in self.bezier[1:]:
path.cubicTo(*[point.center for point in group])
# If there is an ending point, draw a line to it
if self.end_point:
path.lineTo(self.end_connection.center)
end_point = path.currentPosition()
arrowhead = self.angle_arrow(path)
path.lineTo(arrowhead[0])
path.moveTo(end_point)
path.lineTo(arrowhead[1])
path.moveTo(end_point)
try:
# Add the transition label, if any (none for the START edge)
font = QFont('arial', pointSize=8)
width = QFontMetrics(font).width(
self.edge.get('label', 0))
pos = self.mapFromScene(*self.edge['lp'])
#path.addText(pos.x() - width/2, pos.y(),
# font, self.edge['label'])
if not self.text_label:
self.text_label = QGraphicsTextItem(
self.edge.get('label', ''), parent=self)
self.text_label.setX(pos.x() - width / 2)
self.text_label.setY(pos.y())
self.text_label.setFont(font)
self.text_label.show()
except KeyError:
# no label
pass
self.setPath(path)
示例7: setObjectText
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import cubicTo [as 别名]
def setObjectText(self, strng):
"""
TOWRITE
:param `strng`: TOWRITE
:type `strng`: QString
"""
self.objText = strng
textPath = QPainterPath()
font = QFont()
font.setFamily(self.objTextFont)
font.setPointSizeF(self.objTextSize)
font.setBold(self.objTextBold)
font.setItalic(self.objTextItalic)
font.setUnderline(self.objTextUnderline)
font.setStrikeOut(self.objTextStrikeOut)
font.setOverline(self.objTextOverline)
textPath.addText(0., 0., font, strng)
# Translate the path based on the justification.
jRect = textPath.boundingRect() # QRectF
if self.objTextJustify == "Left": textPath.translate(-jRect.left(), 0)
elif self.objTextJustify == "Center": textPath.translate(-jRect.center().x(), 0)
elif self.objTextJustify == "Right": textPath.translate(-jRect.right(), 0)
elif self.objTextJustify == "Aligned": pass # TODO: TextSingleObject Aligned Justification
elif self.objTextJustify == "Middle": textPath.translate(-jRect.center())
elif self.objTextJustify == "Fit": pass # TODO: TextSingleObject Fit Justification
elif self.objTextJustify == "Top Left": textPath.translate(-jRect.topLeft())
elif self.objTextJustify == "Top Center": textPath.translate(-jRect.center().x(), -jRect.top())
elif self.objTextJustify == "Top Right": textPath.translate(-jRect.topRight())
elif self.objTextJustify == "Middle Left": textPath.translate(-jRect.left(), -jRect.top()/2.0)
elif self.objTextJustify == "Middle Center": textPath.translate(-jRect.center().x(), -jRect.top()/2.0)
elif self.objTextJustify == "Middle Right": textPath.translate(-jRect.right(), -jRect.top()/2.0)
elif self.objTextJustify == "Bottom Left": textPath.translate(-jRect.bottomLeft())
elif self.objTextJustify == "Bottom Center": textPath.translate(-jRect.center().x(), -jRect.bottom())
elif self.objTextJustify == "Bottom Right": textPath.translate(-jRect.bottomRight())
# Backward or Upside Down.
if self.objTextBackward or self.objTextUpsideDown:
horiz = 1.0 # qreal
vert = 1.0 # qreal
if self.objTextBackward:
horiz = -1.0
if self.objTextUpsideDown:
vert = -1.0
flippedPath = QPainterPath()
element = QPainterPath.Element
P2 = QPainterPath.Element
P3 = QPainterPath.Element
P4 = QPainterPath.Element
for i in range(0, textPath.elementCount()): # for(int i = 0; i < textPath.elementCount(); ++i)
element = textPath.elementAt(i)
if element.isMoveTo():
flippedPath.moveTo(horiz * element.x, vert * element.y)
elif element.isLineTo():
flippedPath.lineTo(horiz * element.x, vert * element.y)
elif element.isCurveTo():
# start point P1 is not needed
P2 = textPath.elementAt(i) # control point
P3 = textPath.elementAt(i + 1) # control point
P4 = textPath.elementAt(i + 2) # end point
flippedPath.cubicTo(horiz * P2.x, vert * P2.y,
horiz * P3.x, vert * P3.y,
horiz * P4.x, vert * P4.y)
objTextPath = flippedPath
else:
objTextPath = textPath
# Add the grip point to the shape path.
gripPath = objTextPath # QPainterPath
gripPath.connectPath(objTextPath)
gripPath.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002)
self.setObjectPath(gripPath)