本文整理汇总了Python中PyQt4.QtGui.QPolygonF.p2方法的典型用法代码示例。如果您正苦于以下问题:Python QPolygonF.p2方法的具体用法?Python QPolygonF.p2怎么用?Python QPolygonF.p2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QPolygonF
的用法示例。
在下文中一共展示了QPolygonF.p2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setGeometry
# 需要导入模块: from PyQt4.QtGui import QPolygonF [as 别名]
# 或者: from PyQt4.QtGui.QPolygonF import p2 [as 别名]
#.........这里部分代码省略.........
cnt += 1
else:
break
next += 1
if next == len(polygon):
next = 0
#print "%d points missing" % cnt
# First, find total length of wall
length = 0.0
side = sides[prev]
for i in range(len(side)-1):
length += dist(side[i], side[i+1])
diff = length/(cnt+1) # Distance between two points
i = cur
p = side[0]
for j in range(cnt):
l = 0.0
found = False
for k in range(len(side)-1):
dl = dist(side[k], side[k+1])
l += dl
if l > diff*(1+1e-5): # Account for accumulation of small errors
c = (i + j) % len(polygon)
delta = diff-l+dl
p = side[k] + (side[k+1]-side[k])*delta/dl
s1 = side[:k+1] + [p]
s2 = [p] + side[k+1:]
sides[c-1] = s1
sides[c] = s2
side = s2
polygon[c] = p
found = True
break
assert found, "Could not find point in polygon for position %d" % (j+i,)
#p = p + diff
#c = (i+j)%len(polygon)
#polygon[c] = QPointF(p)
cur = next
else:
prev = cur
cur += 1
if cur >= len(polygon):
cur = 0
assert None not in polygon, "Error, some dummy points were not added"
else:
polygon = [p for p in polygon if p is not None]
center = sum(polygon, QPointF(0, 0)) / float(len(polygon))
self.center = center
if len(polygon) > 2:
polygon = QPolygonF(polygon+[polygon[0]])
polygon.translate(-center)
polygon_shape = QPolygonF(polygon_shape + [polygon_shape[0]])
self.polygon_shape = polygon_shape
polygon_shape.translate(-center)
# Translate the sides too
sides = [[p-center for p in s] for s in sides]
self.sides = sides
assert len(sides) == len(polygon)-1
elif len(polygon) == 2:
polygon = QLineF(polygon[0], polygon[1])
polygon.translate(-center)
else:
polygon = None
self.polygon = polygon
self.setPos(center)
params = parameters.instance
self.prepareGeometryChange()
size = params.cell_size
scale = self.scale
height = size*cos(pi/6)*scale[1]
width = size*scale[0]
pos_x = size*cos(pi/3)*scale[0]
self.sel_rect = QRectF(-width, -height, 2*width, 2*height)
if isinstance(polygon, QPolygonF):
self.rect = self.polygon_shape.boundingRect() | self.sel_rect
elif isinstance(polygon, QLineF):
self.rect = QRectF(polygon.p1(), polygon.p2()).normalized() | self.sel_rect
else:
self.rect = self.sel_rect
self.bounding_rect = QRectF(self.rect)
if self.p1 in points and self.p2 in points:
self.division_line = QLineF(points[self.p1].pos()-center, points[self.p2].pos()-center)
else:
self.division_line = None
self.hexagon = QPolygonF([QPointF(-width, 0), QPointF(-pos_x, height), QPointF(pos_x, height),
QPointF(width, 0), QPointF(pos_x, -height), QPointF(-pos_x, -height)])
self.hexagon_path = QPainterPath()
self.hexagon_path.addPolygon(self.hexagon)
s1 = QPainterPath()
if isinstance(self.polygon, QPolygonF):
s1.addPolygon(polygon_shape)
elif isinstance(self.polygon, QLineF):
s1.moveTo(self.polygon.p1())
s1.lineTo(self.polygon.p2())
stroke = QPainterPathStroker()
sel_thick = 3*params.cell_thickness
if sel_thick == 0:
sel_thick = 3
stroke.setWidth(sel_thick)
self.stroke = stroke.createStroke(s1)