本文整理匯總了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)