本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsPolygonItem方法的典型用法代码示例。如果您正苦于以下问题:Python QtWidgets.QGraphicsPolygonItem方法的具体用法?Python QtWidgets.QGraphicsPolygonItem怎么用?Python QtWidgets.QGraphicsPolygonItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets
的用法示例。
在下文中一共展示了QtWidgets.QGraphicsPolygonItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_polygons
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPolygonItem [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
示例2: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPolygonItem [as 别名]
def __init__(self):
super().__init__()
self.ui = Ui_NozzlePreview()
self.ui.setupUi(self)
self.brush = QBrush()
self.brush.setStyle(1)
self.scene = QGraphicsScene(self)
self.upper = QGraphicsPolygonItem()
self.lower = QGraphicsPolygonItem()
self.upper.setBrush(self.brush)
self.lower.setBrush(self.brush)
self.scene.addItem(self.upper)
self.scene.addItem(self.lower)
self.ui.tabCrossSection.setScene(self.scene)
self.ui.tabWidget.currentChanged.connect(self.rescale)
示例3: initMap
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QGraphicsPolygonItem [as 别名]
def initMap(self):
features = json.load(
open("Data/world.json", encoding="utf8")).get("features")
for feature in features:
geometry = feature.get("geometry")
if not geometry:
continue
_type = geometry.get("type")
coordinates = geometry.get("coordinates")
for coordinate in coordinates:
if _type == "Polygon":
polygon = QPolygonF(
[QPointF(latitude, -longitude) for latitude, longitude in coordinate])
item = QGraphicsPolygonItem(polygon)
item.setPen(QPen(self.borderColor, 0))
item.setBrush(QBrush(self.backgroundColor))
item.setPos(0, 0)
self._scene.addItem(item)
elif _type == "MultiPolygon":
for _coordinate in coordinate:
polygon = QPolygonF(
[QPointF(latitude, -longitude) for latitude, longitude in _coordinate])
item = QGraphicsPolygonItem(polygon)
item.setPen(QPen(self.borderColor, 0))
item.setBrush(QBrush(self.backgroundColor))
item.setPos(0, 0)
self._scene.addItem(item)