本文整理汇总了Python中PyQt5.QtGui.QPolygonF.clear方法的典型用法代码示例。如果您正苦于以下问题:Python QPolygonF.clear方法的具体用法?Python QPolygonF.clear怎么用?Python QPolygonF.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QPolygonF
的用法示例。
在下文中一共展示了QPolygonF.clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Arrow
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import clear [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)
示例2: Arrow
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import clear [as 别名]
class Arrow(QGraphicsLineItem):
def __init__(self, startp=Point(), endp=None,
length=60.0, angle=50.0,
color=QtCore.Qt.red, pencolor=QtCore.Qt.green,
startarrow=True):
"""
Initialisation of the class.
"""
self.sc = None
super(Arrow, self).__init__()
self.startp = QtCore.QPointF(startp.x, -startp.y)
self.endp = endp
self.length = length
self.angle = angle
self.startarrow = startarrow
self.allwaysshow = False
self.arrowHead = QPolygonF()
self.setFlag(QGraphicsItem.ItemIsSelectable, False)
self.myColor = color
self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
self.pen.setCosmetic(True)
self.arrowSize = 8.0
def contains_point(self, point):
"""
Arrows cannot be selected. Return maximal distance
"""
return float(0x7fffffff)
def setSelected(self, flag=True, blockSignals=True):
"""
Override inherited function to turn off selection of Arrows.
@param flag: The flag to enable or disable Selection
"""
if self.allwaysshow:
pass
elif flag is True:
self.show()
else:
self.hide()
def setallwaysshow(self, flag=False):
"""
If the directions shall be allwaysshown the parameter
will be set and all paths will be shown.
@param flag: The flag to enable or disable Selection
"""
self.allwaysshow = flag
if flag is True:
self.show()
elif flag is True and self.isSelected():
self.show()
else:
self.hide()
def paint(self, painter, option, widget=None):
"""
Method for painting the arrow.
"""
demat = painter.deviceTransform()
self.sc = demat.m11()
if self.endp is None:
dx = cos(self.angle) * self.length / self.sc
dy = sin(self.angle) * self.length / self.sc
endp = QtCore.QPointF(self.startp.x() - dx, self.startp.y() + dy)
else:
endp = QtCore.QPointF(self.endp.x, -self.endp.y)
arrowSize = self.arrowSize / self.sc
painter.setPen(self.pen)
painter.setBrush(self.myColor)
self.setLine(QtCore.QLineF(endp, self.startp))
line = self.line()
if line.length() != 0:
angle = acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (pi * 2.0) - angle
if self.startarrow:
arrowP1 = line.p2() - QtCore.QPointF(sin(angle + pi / 3.0) * arrowSize,
cos(angle + pi / 3.0) * arrowSize)
arrowP2 = line.p2() - QtCore.QPointF(sin(angle + pi - pi / 3.0) * arrowSize,
cos(angle + pi - pi / 3.0) * arrowSize)
self.arrowHead.clear()
for Point in [line.p2(), arrowP1, arrowP2]:
self.arrowHead.append(Point)
else:
arrowP1 = line.p1() + QtCore.QPointF(sin(angle + pi / 3.0) * arrowSize,
cos(angle + pi / 3.0) * arrowSize)
#.........这里部分代码省略.........
示例3: MovableArrow
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import clear [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:
#.........这里部分代码省略.........
示例4: paintEvent
# 需要导入模块: from PyQt5.QtGui import QPolygonF [as 别名]
# 或者: from PyQt5.QtGui.QPolygonF import clear [as 别名]
#.........这里部分代码省略.........
# 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:
painter.drawPixmap(xofs, round(position.y()),
self.rightArrowIcon)
else:
painter.drawPixmap(xofs, round(position.y()),
self.downArrowIcon)
#Add Bookmarks and Breakpoint
elif block.blockNumber() in self._breakpoints:
linear_gradient = QLinearGradient(
xofs, round(position.y()),
xofs + self.foldArea, round(position.y()) + self.foldArea)
linear_gradient.setColorAt(0, QColor(255, 11, 11))
linear_gradient.setColorAt(1, QColor(147, 9, 9))
painter.setRenderHints(QPainter.Antialiasing, True)
painter.setPen(Qt.NoPen)
painter.setBrush(QBrush(linear_gradient))
painter.drawEllipse(
xofs + 1,
round(position.y()) + 6,
self.foldArea - 1, self.foldArea - 1)
elif block.blockNumber() in self._bookmarks:
linear_gradient = QLinearGradient(
xofs, round(position.y()),
xofs + self.foldArea, round(position.y()) + self.foldArea)
linear_gradient.setColorAt(0, QColor(13, 62, 243))
linear_gradient.setColorAt(1, QColor(5, 27, 106))
painter.setRenderHints(QPainter.Antialiasing, True)
painter.setPen(Qt.NoPen)
painter.setBrush(QBrush(linear_gradient))
painter.drawRoundedRect(
xofs + 1,
round(position.y()) + 6,
self.foldArea - 2, self.foldArea - 1,
3, 3)
block = block.next()# block = next(block)
painter.end()
super(SidebarWidget, self).paintEvent(event)