本文整理汇总了Python中PySide.QtGui.QPainterPath.elementCount方法的典型用法代码示例。如果您正苦于以下问题:Python QPainterPath.elementCount方法的具体用法?Python QPainterPath.elementCount怎么用?Python QPainterPath.elementCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QPainterPath
的用法示例。
在下文中一共展示了QPainterPath.elementCount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PathObject
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import elementCount [as 别名]
#.........这里部分代码省略.........
return
paintPen = self.pen() # QPen
painter.setPen(paintPen)
self.updateRubber(painter)
if option.state & QStyle.State_Selected:
paintPen.setStyle(Qt.DashLine)
if objScene.property(ENABLE_LWT): # .toBool()
paintPen = self.lineWeightPen()
painter.setPen(paintPen)
painter.drawPath(self.objectPath())
def updateRubber(self, painter=None):
"""
TOWRITE
:param `painter`: TOWRITE
:type `painter`: `QPainter`_
"""
# TODO: Path Rubber Modes
# TODO: updateRubber() gripping for PathObject
pass
def vulcanize(self):
"""
TOWRITE
"""
qDebug("PathObject vulcanize()")
self.updateRubber()
self.setObjectRubberMode(OBJ_RUBBER_OFF)
if not self.normalPath.elementCount():
QMessageBox.critical(0, QObject.tr("Empty Path Error"), QObject.tr("The path added contains no points. The command that created this object has flawed logic."))
def mouseSnapPoint(self, mousePoint):
"""
Returns the closest snap point to the mouse point.
:param `mousePoint`: TOWRITE
:type `mousePoint`: `QPointF`_
:rtype: `QPointF`_
"""
return self.scenePos()
def allGripPoints(self):
"""
TOWRITE
:rtype: QList<QPointF>
"""
## QList<QPointF> gripPoints;
## gripPoints << scenePos() # TODO: loop thru all path Elements and return their points
gripPoints = [self.scenePos()]
return gripPoints
def gripEdit(self, before, after):
"""
TOWRITE
:param `before`: TOWRITE
:type `before`: `QPointF`_
:param `after`: TOWRITE
:type `after`: `QPointF`_
示例2: PolylineObject
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import elementCount [as 别名]
#.........这里部分代码省略.........
self.setObjectPos(self.objectRubberPoint("POLYLINE_POINT_0"))
rubberLine = QLineF(self.normalPath.currentPosition(), self.mapFromScene(self.objectRubberPoint("")))
if painter:
self.drawRubberLine(rubberLine, painter, "VIEW_COLOR_CROSSHAIR")
ok = False # bool
numStr = self.objectRubberText("POLYLINE_NUM_POINTS") # QString
if not numStr:
return
try:
num = int(numStr)
except ValueError:
return
appendStr = '' # QString
rubberPath = QPainterPath()
for i in range(1, num): # for(int i = 1; i <= num; i++)
appendStr = "POLYLINE_POINT_" + "%s" % i # QString().setNum(i);
appendPoint = self.mapFromScene(self.objectRubberPoint(appendStr)) # QPointF
rubberPath.lineTo(appendPoint)
self.updatePath(rubberPath)
# Ensure the path isn't updated until the number of points is changed again.
self.setObjectRubberText("POLYLINE_NUM_POINTS", "")
elif rubberMode == OBJ_RUBBER_GRIP:
if painter:
elemCount = self.normalPath.elementCount() # int
gripPoint = self.objectRubberPoint("GRIP_POINT") # QPointF
if self.gripIndex == -1:
self.gripIndex = self.findIndex(gripPoint)
if self.gripIndex == -1:
return
if not self.gripIndex: # First.
ef = self.normalPath.elementAt(1) # QPainterPath::Element
efPoint = QPointF(ef.x, ef.y) # QPointF
painter.drawLine(efPoint, self.mapFromScene(self.objectRubberPoint("")))
elif self.gripIndex == elemCount - 1: # Last.
el = self.normalPath.elementAt(self.gripIndex - 1) # QPainterPath::Element
elPoint = QPointF(el.x, el.y) # QPointF
painter.drawLine(elPoint, self.mapFromScene(self.objectRubberPoint("")))
else: # Middle.
em = self.normalPath.elementAt(self.gripIndex - 1) # QPainterPath::Element
en = self.normalPath.elementAt(self.gripIndex + 1) # QPainterPath::Element
emPoint = QPointF(em.x, em.y) # QPointF
enPoint = QPointF(en.x, en.y) # QPointF
painter.drawLine(emPoint, self.mapFromScene(self.objectRubberPoint("")))
painter.drawLine(enPoint, self.mapFromScene(self.objectRubberPoint("")))
rubLine = QLineF(self.mapFromScene(gripPoint), self.mapFromScene(self.objectRubberPoint("")))
self.drawRubberLine(rubLine, painter, "VIEW_COLOR_CROSSHAIR")
def vulcanize(self):
"""
示例3: setObjectText
# 需要导入模块: from PySide.QtGui import QPainterPath [as 别名]
# 或者: from PySide.QtGui.QPainterPath import elementCount [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)