本文整理汇总了Python中PyQt5.QtGui.QPolygonF方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QPolygonF方法的具体用法?Python QtGui.QPolygonF怎么用?Python QtGui.QPolygonF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui
的用法示例。
在下文中一共展示了QtGui.QPolygonF方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_polygons
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def add_polygons(self, polygons, color = '#A8F22A', alpha = 1):
qcolor = QColor()
qcolor.setNamedColor(color)
qcolor.setAlphaF(alpha)
for points in polygons:
qpoly = QPolygonF( [QPointF(p[0], p[1]) for p in points] )
scene_poly = self.scene.addPolygon(qpoly)
scene_poly.setBrush(qcolor)
scene_poly.setPen(self.pen)
self.scene_polys.append(scene_poly)
# Update custom bounding box
sr = scene_poly.sceneBoundingRect()
if len(self.scene_polys) == 1:
self.scene_xmin = sr.left()
self.scene_xmax = sr.right()
self.scene_ymin = sr.top()
self.scene_ymax = sr.bottom()
else:
self.scene_xmin = min(self.scene_xmin, sr.left())
self.scene_xmax = max(self.scene_xmax, sr.right())
self.scene_ymin = min(self.scene_ymin, sr.top())
self.scene_ymax = max(self.scene_ymax, sr.bottom())
示例2: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def __init__(self, geometry=QtGui.QPolygonF(),
brush=QtGui.QBrush(QtCore.Qt.NoBrush),
pen=QtGui.QPen(QtCore.Qt.NoPen)):
"""
Initialize the polygon.
:type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
:type brush: QBrush
:type pen: QPen
"""
self._geometry = geometry
self._brush = brush
self._pen = pen
#############################################
# INTERFACE
#################################
示例3: draw_polygons
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def draw_polygons(self):
sf = shapefile.Reader(self.shapefile)
polygons = sf.shapes()
for polygon in polygons:
# convert shapefile geometries into shapely geometries
# to extract the polygons of a multipolygon
polygon = shapely.geometry.shape(polygon)
# if it is a polygon, we use a list to make it iterable
if polygon.geom_type == 'Polygon':
polygon = [polygon]
for land in polygon:
qt_polygon = QtGui.QPolygonF()
longitudes, latitudes = land.exterior.coords.xy
for lon, lat in zip(longitudes, latitudes):
px, py = self.to_canvas_coordinates(lon, lat)
if px > 1e+10:
continue
qt_polygon.append(QtCore.QPointF(px, py))
polygon_item = QtWidgets.QGraphicsPolygonItem(qt_polygon)
polygon_item.setBrush(self.land_brush)
polygon_item.setPen(self.land_pen)
polygon_item.setZValue(1)
yield polygon_item
示例4: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def __init__(self, y, x):
hex_center_x, hex_center_y = indextoHex(y, x)
center = QtCore.QPointF(hex_center_x, hex_center_y)
points = [
HEX_SCALE * HEX_SIDE_HALF * QtCore.QPointF(-1, 0) + center,
HEX_SCALE * HEX_SIDE_HALF * QtCore.QPointF(-0.5, sqrt(3) / 2)
+ center,
HEX_SCALE * HEX_SIDE_HALF * QtCore.QPointF(0.5, sqrt(3) / 2)
+ center,
HEX_SCALE * HEX_SIDE_HALF * QtCore.QPointF(1, 0) + center,
HEX_SCALE * HEX_SIDE_HALF * QtCore.QPointF(0.5, -sqrt(3) / 2)
+ center,
HEX_SCALE * HEX_SIDE_HALF * QtCore.QPointF(-0.5, -sqrt(3) / 2)
+ center,
]
hexagonPointsF = QtGui.QPolygonF(points)
super().__init__(hexagonPointsF)
self.setPen(HEX_PEN)
self.setBrush(defaultcolor) # initialize all as grey
示例5: draw_food_contour
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def draw_food_contour(self, image):
if self.food_coordinates is None or not self.ui.checkBox_showFood.isChecked():
return
painter = QPainter()
painter.begin(image)
penwidth = max(1, max(image.height(), image.width()) // 800)
col = Qt.darkMagenta
p = QPolygonF()
for x,y in self.food_coordinates:
p.append(QPointF(x,y))
pen = QPen()
pen.setWidth(penwidth)
pen.setColor(col)
painter.setPen(pen)
painter.drawPolyline(p)
painter.end()
示例6: paintEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def paintEvent(self, event):
# 绘制默认的样式
super(SplitterHandle, self).paintEvent(event)
# 绘制顶部扩展按钮
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.setPen(Qt.red)
# 画矩形
painter.drawRect(0, 0, self.width(), 24)
# 画三角形
painter.setBrush(Qt.red)
painter.drawPolygon(QPolygonF([
QPointF(0, (24 - 8) / 2),
QPointF(self.width() - 2, 24 / 2),
QPointF(0, (24 + 8) / 2)
]))
示例7: add_port
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def add_port(self, port, is_subport = False):
if (port.width is None) or (port.width == 0):
x,y = port.midpoint
cs = 1 # cross size
pn = QPointF(x, y+cs)
ps = QPointF(x, y-cs)
pe = QPointF(x+cs, y)
pw = QPointF(x-cs, y)
qline1 = self.scene.addLine(QLineF(pn, ps))
qline2 = self.scene.addLine(QLineF(pw, pe))
port_shapes = [qline1,qline2]
else:
point1, point2 = port.endpoints
point1 = QPointF(point1[0], point1[1])
point2 = QPointF(point2[0], point2[1])
qline = self.scene.addLine(QLineF(point1, point2))
arrow_points = np.array([[0,0],[10,0],[6,4],[6,2],[0,2]])/(40)*port.width
arrow_qpoly = QPolygonF( [QPointF(p[0], p[1]) for p in arrow_points] )
port_scene_poly = self.scene.addPolygon(arrow_qpoly)
port_scene_poly.setRotation(port.orientation)
port_scene_poly.moveBy(port.midpoint[0], port.midpoint[1])
port_shapes = [qline,port_scene_poly]
qtext = self.scene.addText(str(port.name), self.portfont)
port_items = port_shapes + [qtext]
rad = port.orientation*np.pi/180
x,y = port.endpoints[0]*1/4 + port.endpoints[1]*3/4 + np.array([np.cos(rad), np.sin(rad)])*port.width/8
# x,y = port.midpoint[0], port.midpoint[1]
# x,y = x - qtext.boundingRect().width()/2, y - qtext.boundingRect().height()/2
qtext.setPos(QPointF(x,y))
qtext.setFlag(QGraphicsItem.ItemIgnoresTransformations)
if not is_subport:
[shape.setPen(self.portpen) for shape in port_shapes]
qtext.setDefaultTextColor(self.portfontcolor)
self.portitems += port_items
else:
[shape.setPen(self.subportpen) for shape in port_shapes]
qtext.setDefaultTextColor(self.subportfontcolor)
self.subportitems += port_items
# self.portlabels.append(qtext)
示例8: turn
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def turn():
global epi_x, epi_y, p1, p2, p3, p4, rect
write_log()
teta = math.radians(window.spin_deg.value())
t_x = window.spin_turn_x.value()
t_y = window.spin_turn_y.value()
scene.clear()
rect_t = QPolygonF(4)
p1 = [t_x + (p1[0] - t_x) * math.cos(teta) + (p1[1] - t_y) * math.sin(teta),
t_y - (p1[0] - t_x) * math.sin(teta) + (p1[1] - t_y) * math.cos(teta)]
p2 = [t_x + (p2[0] - t_x) * math.cos(teta) + (p2[1] - t_y) * math.sin(teta),
t_y - (p2[0] - t_x) * math.sin(teta) + (p2[1] - t_y) * math.cos(teta)]
p3 = [t_x + (p3[0] - t_x) * math.cos(teta) + (p3[1] - t_y) * math.sin(teta),
t_y - (p3[0] - t_x) * math.sin(teta) + (p3[1] - t_y) * math.cos(teta)]
p4 = [t_x + (p4[0] - t_x) * math.cos(teta) + (p4[1] - t_y) * math.sin(teta),
t_y - (p4[0] - t_x) * math.sin(teta) + (p4[1] - t_y) * math.cos(teta)]
rect[0] = QPointF(p1[0], p1[1])
rect[1] = QPointF(p2[0], p2[1])
rect[2] = QPointF(p3[0], p3[1])
rect[3] = QPointF(p4[0], p4[1])
scene.addPolygon(rect, pen=p, brush=b)
l = len(epi_x)
for i in range(l):
x1 = t_x + (epi_x[i] - t_x) * math.cos(teta) + (epi_y[i] - t_y) * math.sin(teta)
y1 = t_y - (epi_x[i] - t_x) * math.sin(teta) + (epi_y[i] - t_y) * math.cos(teta)
epi_x[i] = x1
epi_y[i] = y1
scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p)
示例9: sutherland_hodgman
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def sutherland_hodgman(clip, pol, norm):
# дублируем начальную вершину отсекателя в конец
clip.append(clip[0])
s = None
f = None
# цикл по вершинам отсекателя
for i in range(len(clip) - 1):
new = [] # новый массив вершин
for j in range(len(pol)): # цикл по вершинам многоугольника
if j == 0:
f = pol[j]
else:
t = is_intersection([s, pol[j]], [clip[i], clip[i + 1]], norm)
if t:
new.append(t)
s = pol[j]
if is_visiable(s, clip[i], clip[i + 1], norm):
new.append(s)
if len(new) != 0:
t = is_intersection([s, f], [clip[i], clip[i + 1]], norm)
if t:
new.append(t)
pol = copy.deepcopy(new)
if len(pol) == 0:
return False
else:
return QPolygonF(pol)
示例10: createArea
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def createArea(p1, p2, degrees, size):
"""
Creates an area between the given QPointF and according to the given angle and size.
:type p1: QPointF
:type p2: QPointF
:type degrees: float
:type size: int
:rtype: QPolygonF
"""
rad = math.radians(degrees)
x = size / 2 * math.sin(rad)
y = size / 2 * math.cos(rad)
a = QtCore.QPointF(+x, +y)
b = QtCore.QPointF(-x, -y)
return QtGui.QPolygonF([p1 + a, p1 + b, p2 + b, p2 + a])
示例11: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def __init__(self, **kwargs):
"""
Initialize the edge.
"""
super().__init__(**kwargs)
self.tail = Polygon(QtGui.QPolygonF())
#############################################
# INTERFACE
#################################
示例12: createHead
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def createHead(p1, angle, size):
"""
Create the head polygon.
:type p1: QPointF
:type angle: float
:type size: int
:rtype: QPolygonF
"""
rad = radians(angle)
p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
p3 = p1 - QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
return QtGui.QPolygonF([p1, p2, p3])
示例13: createTail
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def createTail(p1, angle, size):
"""
Create the tail polygon.
:type p1: QPointF
:type angle: float
:type size: int
:rtype: QPolygonF
"""
rad = radians(angle)
p2 = p1 + QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
p3 = p1 + QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
return QtGui.QPolygonF([p1, p2, p3])
示例14: createHead
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def createHead(p1, angle, size):
"""
Create the head polygon.
:type p1: QPointF
:type angle: float
:type size: int
:rtype: QPolygonF
"""
rad = radians(angle)
p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 4.0) * size, cos(rad + M_PI / 4.0) * size)
p3 = p2 - QtCore.QPointF(sin(rad + 3.0 / 4.0 * M_PI) * size, cos(rad + 3.0 / 4.0 * M_PI) * size)
p4 = p3 - QtCore.QPointF(sin(rad - 3.0 / 4.0 * M_PI) * size, cos(rad - 3.0 / 4.0 * M_PI) * size)
return QtGui.QPolygonF([p1, p2, p3, p4])
示例15: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygonF [as 别名]
def __init__(self, source, target=None, breakpoints=None, **kwargs):
"""
Initialize the edge.
:type source: AbstractNode
:type target: AbstractNode
:type breakpoints: list
"""
super().__init__(**kwargs)
self.source = source
self.target = target
self.anchors = {} # {AbstractNode: Polygon}
self.breakpoints = breakpoints or [] # [QtCore.QPointF]
self.handles = [] # [Polygon]
self.head = Polygon(QtGui.QPolygonF())
self.path = Polygon(QtGui.QPainterPath())
self.selection = Polygon(QtGui.QPainterPath())
self.mp_AnchorNode = None
self.mp_AnchorNodePos = None
self.mp_BreakPoint = None
self.mp_BreakPointPos = None
self.mp_Pos = None
self.setAcceptHoverEvents(True)
self.setCacheMode(AbstractItem.DeviceCoordinateCache)
self.setFlag(AbstractItem.ItemIsSelectable, True)
#############################################
# INTERFACE
#################################