本文整理汇总了Python中PyQt5.QtGui.QPolygonF.append方法的典型用法代码示例。如果您正苦于以下问题:Python QPolygonF.append方法的具体用法?Python QPolygonF.append怎么用?Python QPolygonF.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QPolygonF
的用法示例。
在下文中一共展示了QPolygonF.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawZig
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def drawZig(qp, x, y, width, height):
qp = qp # type: QPainter
pointsCoord = [[x, y + height], [x + width * 0.33, y], [x + width * 0.66, y + height], [x + width, y]]
trianglePolygon = QPolygonF()
for i in pointsCoord:
trianglePolygon.append(QPointF(i[0], i[1]))
qp.drawPolygon(trianglePolygon)
示例2: paint
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def paint(self, painter, option, widget):
if self.line().length() == 0:
return
pen = self.pen()
pen.setColor(constants.LINECOLOR)
painter.setPen(pen)
painter.setBrush(constants.LINECOLOR)
arrow_size = 10.0
angle = math.acos(self.line().dx() / self.line().length())
if self.line().dy() >= 0:
angle = (math.pi * 2) - angle
arrow_p1 = self.line().p2() - QPointF(math.sin(angle + math.pi / 2.5) * arrow_size,
math.cos(angle + math.pi / 2.5) * arrow_size)
arrow_p2 = self.line().p2() - QPointF(math.sin(angle + math.pi - math.pi / 2.5) * arrow_size,
math.cos(angle + math.pi - math.pi / 2.5) * arrow_size)
arrow_head = QPolygonF()
arrow_head.append(self.line().p2())
arrow_head.append(arrow_p1)
arrow_head.append(arrow_p2)
painter.drawLine(self.line())
painter.drawPolygon(arrow_head)
示例3: __readPolygon
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def __readPolygon(self):
atts = self.xml.attributes()
points = atts.value("points")
pointsList = list(filter(lambda x:x.strip()!='', points.split(' ')))
polygon = QPolygonF()
ok = True
for point in pointsList:
try:
x, y = point.split(',')
except:
ok = False
break
x, ok = Float2(x)
if (not ok):
break
y, ok = Float2(y)
if (not ok):
break
polygon.append(QPointF(x, y))
if (not ok):
self.xml.raiseError(self.tr("Invalid points data for polygon"))
self.xml.skipCurrentElement()
return polygon
示例4: toPolygon
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def toPolygon(self, variant):
polygon = QPolygonF()
for pointVariant in variant:
pointVariantMap = pointVariant
pointX = pointVariantMap.get("x",0.0)
pointY = pointVariantMap.get("y",0.0)
polygon.append(QPointF(pointX, pointY))
return polygon
示例5: startNewMapObject
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def startNewMapObject(self, pos, objectGroup):
super().startNewMapObject(pos, objectGroup)
newMapObject = self.mNewMapObjectItem.mapObject()
polygon = QPolygonF()
polygon.append(QPointF())
newMapObject.setPolygon(polygon)
polygon.append(QPointF()) # The last point is connected to the mouse
self.mOverlayPolygonObject.setPolygon(polygon)
self.mOverlayPolygonObject.setShape(newMapObject.shape())
self.mOverlayPolygonObject.setPosition(pos)
self.mOverlayPolygonItem = MapObjectItem(self.mOverlayPolygonObject, self.mapDocument(), self.mObjectGroupItem)
示例6: pixelRectToScreenPolygon
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def pixelRectToScreenPolygon(self, rect):
polygon = QPolygonF()
polygon.append(QPointF(self.pixelToScreenCoords_(rect.topLeft())))
polygon.append(QPointF(self.pixelToScreenCoords_(rect.topRight())))
polygon.append(QPointF(self.pixelToScreenCoords_(rect.bottomRight())))
polygon.append(QPointF(self.pixelToScreenCoords_(rect.bottomLeft())))
return polygon
示例7: updatePath
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def updatePath(self):
try:
attrs = self.stackedWidget.currentWidget().get_attributes()
attrs.keys()
except Exception as e:
msg = 'Tracking Lib. Attributes Error:\n{}'.format(e)
self.generateCriticalMessage(msg)
return
if 'position' in attrs:
self.trackingPathGroup.setPoints(self.currentFrameNo)
if 'arrow' in attrs:
for i, arrow_item in enumerate(self.item_dict['arrow']):
begin = self.df['position'].loc[self.currentFrameNo, i].as_matrix()
end = self.df['arrow'].loc[self.currentFrameNo, i].as_matrix()
arrow_item.setPosition(begin, end)
if 'path' in attrs:
for path_item, path_data in zip(self.item_dict['path'], self.data_dict['path'][self.currentFrameNo]):
poly = QPolygonF()
for p in path_data:
poly.append(QPointF(*p))
painter_path = QPainterPath()
painter_path.addPolygon(poly)
path_item.setPath(painter_path)
pen = QPen(Qt.blue)
pen.setWidth(2)
path_item.setPen(pen)
if 'polygon' in attrs:
for path_item, path_data in zip(self.item_dict['polygon'], self.data_dict['polygon'][self.currentFrameNo]):
poly = QPolygonF()
for p in path_data:
poly.append(QPointF(*p))
painter_path = QPainterPath()
painter_path.addPolygon(poly)
path_item.setPath(painter_path)
pen = QPen(Qt.black)
pen.setWidth(1)
path_item.setPen(pen)
if 'rect' in attrs:
for rect_item, rect in zip(self.item_dict['rect'], self.data_dict['rect'][self.currentFrameNo]):
rect_item.setRect(QRectF(QPointF(*rect[0]), QPointF(*rect[1])))
示例8: paint
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def paint(self, painter, option, widget=None):
"""
Public method to paint the item in local coordinates.
@param painter reference to the painter object (QPainter)
@param option style options (QStyleOptionGraphicsItem)
@param widget optional reference to the widget painted on (QWidget)
"""
if (option.state & QStyle.State_Selected) == \
QStyle.State(QStyle.State_Selected):
width = 2
else:
width = 1
# draw the line first
line = QLineF(self._origin, self._end)
painter.setPen(
QPen(Qt.black, width, Qt.SolidLine, Qt.FlatCap, Qt.MiterJoin))
painter.drawLine(line)
# draw the arrow head
arrowAngle = self._type * ArrowheadAngleFactor
slope = math.atan2(line.dy(), line.dx())
# Calculate left arrow point
arrowSlope = slope + arrowAngle
a1 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
self._end.y() - self._halfLength * math.sin(arrowSlope))
# Calculate right arrow point
arrowSlope = slope - arrowAngle
a2 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
self._end.y() - self._halfLength * math.sin(arrowSlope))
if self._filled:
painter.setBrush(Qt.black)
else:
painter.setBrush(Qt.white)
polygon = QPolygonF()
polygon.append(line.p2())
polygon.append(a1)
polygon.append(a2)
painter.drawPolygon(polygon)
示例9: tileRectToScreenPolygon
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def tileRectToScreenPolygon(self, rect):
tileWidth = self.map().tileWidth()
tileHeight = self.map().tileHeight()
topRight = self.tileToScreenCoords_(rect.topRight())
bottomRight = self.tileToScreenCoords_(rect.bottomRight())
bottomLeft = self.tileToScreenCoords_(rect.bottomLeft())
polygon = QPolygonF()
polygon.append(QPointF(self.tileToScreenCoords_(rect.topLeft())))
polygon.append(QPointF(topRight.x() + tileWidth / 2, topRight.y() + tileHeight / 2))
polygon.append(QPointF(bottomRight.x(), bottomRight.y() + tileHeight))
polygon.append(QPointF(bottomLeft.x() - tileWidth / 2, bottomLeft.y() + tileHeight / 2))
return polygon
示例10: _setSpeeds
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
def _setSpeeds(self, speeds):
polygon = QPolygonF()
polygon.append(QPointF(0, self.SIZE[1])) # start the polygon
nSamples = len(speeds)
xPerSample = self.SIZE[0] / nSamples
for i, speed in enumerate(speeds):
y = self._translateSpeedToPosY(speed)
polygon.append(QPointF(xPerSample * i, y))
polygon.append(QPointF(xPerSample * (i+1), y))
polygon.append(QPointF(*self.SIZE)) # close the polygon
self._speedsPolygon.setPolygon(polygon)
示例11: paintEvent
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
#.........这里部分代码省略.........
font_metrics.width(str(line_count)) - 3,
round(position.y()) + font_metrics.ascent() +
font_metrics.descent() - 1,
str(line_count))
# Remove the bold style if it was set previously.
if bold:
font = painter.font()
font.setBold(False)
painter.setFont(font)
if error:
font = painter.font()
font.setItalic(False)
font.setUnderline(False)
painter.setFont(font)
block = block.next()
self.highest_line = line_count
#Code Folding
xofs = self.width() - self.foldArea
painter.fillRect(xofs, 0, self.foldArea, self.height(),
QColor(resources.CUSTOM_SCHEME.get('fold-area',
resources.COLOR_SCHEME['fold-area'])))
if self.foldArea != self.rightArrowIcon.width():
polygon = QPolygonF()
self.rightArrowIcon = QPixmap(self.foldArea, self.foldArea)
self.rightArrowIcon.fill(Qt.transparent)
self.downArrowIcon = QPixmap(self.foldArea, self.foldArea)
self.downArrowIcon.fill(Qt.transparent)
polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.25))
polygon.append(QPointF(self.foldArea * 0.4, self.foldArea * 0.75))
polygon.append(QPointF(self.foldArea * 0.8, self.foldArea * 0.5))
iconPainter = QPainter(self.rightArrowIcon)
iconPainter.setRenderHint(QPainter.Antialiasing)
iconPainter.setPen(Qt.NoPen)
iconPainter.setBrush(QColor(
resources.CUSTOM_SCHEME.get('fold-arrow',
resources.COLOR_SCHEME['fold-arrow'])))
iconPainter.drawPolygon(polygon)
polygon.clear()
polygon.append(QPointF(self.foldArea * 0.25, self.foldArea * 0.4))
polygon.append(QPointF(self.foldArea * 0.75, self.foldArea * 0.4))
polygon.append(QPointF(self.foldArea * 0.5, self.foldArea * 0.8))
iconPainter = QPainter(self.downArrowIcon)
iconPainter.setRenderHint(QPainter.Antialiasing)
iconPainter.setPen(Qt.NoPen)
iconPainter.setBrush(QColor(
resources.CUSTOM_SCHEME.get('fold-arrow',
resources.COLOR_SCHEME['fold-arrow'])))
iconPainter.drawPolygon(polygon)
block = self.edit.firstVisibleBlock()
while block.isValid():
position = self.edit.blockBoundingGeometry(
block).topLeft() + viewport_offset
#Check if the position of the block is outside of the visible area
if position.y() > page_bottom:
break
if pattern.match(block.text()) and block.isVisible():
if block.blockNumber() in self._foldedBlocks:
示例12: Arrow
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
class Arrow(QGraphicsLineItem):
def __init__(self, start_item, end_item, parent=None):
super(Arrow, self).__init__(parent)
self.arrowHead = QPolygonF()
self.my_start_item = start_item
self.my_end_item = end_item
self.setFlag(QGraphicsItem.ItemIsSelectable, True)
self.my_color = Qt.black
self.setPen(QPen(self.my_color, 2, Qt.SolidLine, Qt.RoundCap,
Qt.RoundJoin))
def set_color(self, color):
self.my_color = color
def start_item(self):
return self.my_start_item
def end_item(self):
return self.my_end_item
def boundingRect(self):
extra = (self.pen().width() + 20) / 2.0
p1 = self.line().p1()
p2 = self.line().p2()
return QRectF(p1, QSizeF(p2.x() - p1.x(), p2.y() - p1.y())).normalized().adjusted(-extra, -extra, extra, extra)
def shape(self):
path = super(Arrow, self).shape()
path.addPolygon(self.arrowHead)
return path
def update_position(self):
line = QLineF(self.mapFromItem(self.my_start_item, 0, 0), self.mapFromItem(self.my_end_item, 0, 0))
self.setLine(line)
def paint(self, painter, option, widget=None):
if self.my_start_item.collidesWithItem(self.my_end_item):
return
my_start_item = self.my_start_item
my_end_item = self.my_end_item
my_color = self.my_color
my_pen = self.pen()
my_pen.setColor(self.my_color)
arrow_size = 20.0
painter.setPen(my_pen)
painter.setBrush(my_color)
center_line = QLineF(my_start_item.pos(), my_end_item.pos())
end_polygon = my_end_item.polygon
p1 = end_polygon.first() + my_end_item.pos()
intersect_point = QPointF()
for i in end_polygon:
p2 = i + my_end_item.pos()
poly_line = QLineF(p1, p2)
intersect_type = poly_line.intersect(center_line, intersect_point)
if intersect_type == QLineF.BoundedIntersection:
break
p1 = p2
self.setLine(QLineF(intersect_point, my_start_item.pos()))
line = self.line()
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (math.pi * 2) - angle
arrow_p1 = line.p1() + QPointF(math.sin(angle + math.pi / 3.0) * arrow_size,
math.cos(angle + math.pi / 3) * arrow_size)
arrow_p2 = line.p1() + QPointF(math.sin(angle + math.pi - math.pi / 3.0) * arrow_size,
math.cos(angle + math.pi - math.pi / 3.0) * arrow_size)
self.arrowHead.clear()
for point in [line.p1(), arrow_p1, arrow_p2]:
self.arrowHead.append(point)
painter.drawLine(line)
painter.drawPolygon(self.arrowHead)
if self.isSelected():
painter.setPen(QPen(my_color, 1, Qt.DashLine))
my_line = QLineF(line)
my_line.translate(0, 4.0)
painter.drawLine(my_line)
my_line.translate(0, -8.0)
painter.drawLine(my_line)
示例13: QRectF
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
_yScale = styles.PATH_XOVER_LINE_SCALE_Y # control point y constant
_rect = QRectF(0, 0, _BASE_WIDTH, _BASE_WIDTH)
_blankRect = QRectF(0, 0, 2*_BASE_WIDTH, _BASE_WIDTH)
PPL5 = QPainterPath() # Left 5' PainterPath
PPR5 = QPainterPath() # Right 5' PainterPath
PPL3 = QPainterPath() # Left 3' PainterPath
PPR3 = QPainterPath() # Right 3' PainterPath
# set up PPL5 (left 5' blue square)
PPL5.addRect(0.25*_BASE_WIDTH, 0.125*_BASE_WIDTH, 0.75*_BASE_WIDTH, 0.75*_BASE_WIDTH)
# set up PPR5 (right 5' blue square)
PPR5.addRect(0, 0.125*_BASE_WIDTH, 0.75*_BASE_WIDTH, 0.75*_BASE_WIDTH)
# set up PPL3 (left 3' blue triangle)
L3_POLY = QPolygonF()
L3_POLY.append(QPointF(_BASE_WIDTH, 0))
L3_POLY.append(QPointF(0.25*_BASE_WIDTH, 0.5*_BASE_WIDTH))
L3_POLY.append(QPointF(_BASE_WIDTH, _BASE_WIDTH))
PPL3.addPolygon(L3_POLY)
# set up PPR3 (right 3' blue triangle)
R3_POLY = QPolygonF()
R3_POLY.append(QPointF(0, 0))
R3_POLY.append(QPointF(0.75*_BASE_WIDTH, 0.5*_BASE_WIDTH))
R3_POLY.append(QPointF(0, _BASE_WIDTH))
PPR3.addPolygon(R3_POLY)
class ForcedXoverNode3(QGraphicsRectItem):
"""
This is a QGraphicsRectItem to allow actions and also a
QGraphicsSimpleTextItem to allow a label to be drawn
示例14: MovableArrow
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
class MovableArrow(QGraphicsLineItem):
def __init__(self, parent=None):
super(MovableArrow, self).__init__(parent)
self.setZValue(1000)
self.arrowHead = QPolygonF()
self.begin = np.array([0.0, 0.0])
self.end =np.array([10.0, 10.0])
self.myColor = Qt.black
self.setPen(QPen(self.myColor, 5))
self.arrowSize = 5
self.setOpacity(0.4)
self.isMousePressed = False
self.setFlags(QGraphicsItem.ItemIsSelectable |
QGraphicsItem.ItemIsFocusable |
QGraphicsItem.ItemIsMovable |
QGraphicsItem.ItemSendsGeometryChanges)
self.angleFixedFlag = False
self.objectName = None
def boundingRect(self):
extra = (self.pen().width() + 20) / 2.0
size = QSizeF(
1.3*(self.line().p1().x() - self.line().p2().x()),
1.3*(self.line().p1().y() - self.line().p2().y())
)
return QRectF(self.line().p2(), size).normalized().adjusted(-extra, -extra, extra, extra)
def shape(self):
path = super(MovableArrow, self).shape()
path.addPolygon(self.arrowHead)
return path
def setColor(self, colorArray):
self.myColor = QColor(*colorArray)
def updatePosition(self):
line = QLineF(QPointF(*self.end), QPointF(*self.begin))
self.setLine(line)
self.shape()
def paint(self, painter, option, widget=None):
self.updatePosition()
myPen = self.pen()
myPen.setColor(self.myColor)
painter.setPen(myPen)
# painter.setBrush(self.myColor)
try:
angle = np.arccos(self.line().dx() / self.line().length())
except ZeroDivisionError:
angle = 0.0
if self.line().dy() >= 0:
angle = (np.pi * 2) - angle;
l = self.line().length()*0.1
arrowP0 = self.line().p1() - QPointF(self.line().dx()/l, self.line().dy()/l)
arrowP1 = self.line().p1() + QPointF(np.sin(angle + np.pi / 6) * self.arrowSize,
np.cos(angle + np.pi / 6) * self.arrowSize)
arrowP2 = self.line().p1() + QPointF(np.sin(angle + np.pi - np.pi / 6) * self.arrowSize,
np.cos(angle + np.pi - np.pi / 6) * self.arrowSize)
self.arrowHead.clear();
self.arrowHead.append(arrowP0)
self.arrowHead.append(arrowP1)
self.arrowHead.append(arrowP2)
# painter.drawConvexPolygon(self.arrowHead)
arrow = QPainterPath()
arrow.addPolygon(self.arrowHead)
painter.fillPath(arrow, QBrush(self.myColor))
painter.drawLine(self.line())
self.shape()
def mousePressEvent(self, event):
self.isMousePressed = True
self.mousePressedPos = event.scenePos()
self.end_old = self.end.copy()
super(MovableArrow, self).mousePressEvent(event)
def mouseMoveEvent(self, event):
mouseCursorPos = event.scenePos()
#mouseCursorPos = event.Pos()
if self.isMousePressed:
x = mouseCursorPos.x() - self.mousePressedPos.x()
y = mouseCursorPos.y() - self.mousePressedPos.y()
delta = np.array([x,y])
# angle = ang(self.begin, self.end+delta)
if self.angleFixedFlag == False:
self.end[:] = self.end_old + delta
else:
#.........这里部分代码省略.........
示例15: import
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import append [as 别名]
QGraphicsPathItem,
QGraphicsRectItem
)
from cadnano.gui.palette import (
getBrushObj,
getColorObj,
getNoPen,
getPenObj
)
from . import gridstyles as styles
PXI_PP_ITEM_WIDTH = IW = 2.0 # 1.5
TRIANGLE = QPolygonF()
TRIANGLE.append(QPointF(0, 0))
TRIANGLE.append(QPointF(0.75*IW, 0.5*IW))
TRIANGLE.append(QPointF(0, IW))
TRIANGLE.append(QPointF(0, 0))
# TRIANGLE.translate(-0.75*IW, -0.5*IW)
TRIANGLE.translate(-0.25*IW, -0.5*IW)
PXI_RECT = QRectF(0, 0, IW, IW)
T90, T270 = QTransform(), QTransform()
T90.rotate(90)
T270.rotate(270)
FWDPXI_PP, REVPXI_PP = QPainterPath(), QPainterPath()
FWDPXI_PP.addPolygon(T90.map(TRIANGLE))
REVPXI_PP.addPolygon(T270.map(TRIANGLE))
# FWDPXI_PP.moveTo(-0.5*IW, 0.7*IW)