本文整理汇总了Python中PyQt4.QtGui.QPolygonF类的典型用法代码示例。如果您正苦于以下问题:Python QPolygonF类的具体用法?Python QPolygonF怎么用?Python QPolygonF使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPolygonF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_selection
def _add_selection(self, item):
"""Add selection rooted at item
"""
outline = self._selection_poly(item)
selection_item = QGraphicsPolygonItem(self)
# selection_item = QGraphicsPathItem(self)
selection_item.setPos(self.contentsRect().topLeft())
# selection_item.setPen(QPen(Qt.NoPen))
selection_item.setPen(make_pen(width=1, cosmetic=True))
transform = self._itemgroup.transform()
path = transform.map(outline)
margin = 4
if item.node.is_leaf:
path = QPolygonF(path.boundingRect()
.adjusted(-margin, -margin, margin, margin))
else:
pass
# ppath = QPainterPath()
# ppath.addPolygon(path)
# path = path_outline(ppath, width=margin).toFillPolygon()
selection_item.setPolygon(path)
# selection_item.setPath(path_outline(path, width=4))
selection_item.unscaled_path = outline
self._selection[item] = selection_item
item.setSelected(True)
示例2: __init__
def __init__(self, parent):
points = QPolygonF()
self._mediator = ArrowMediator()
for poly in (QPointF(7,0), QPointF(-7,7), QPointF(-5,2), QPointF(-11,2),
QPointF(-11,-2), QPointF(-5,-2), QPointF(-7,-7)):
points.append(poly)
QGraphicsPolygonItem.__init__(self, points, parent)
self.setPen(Qt.darkCyan)
self.setBrush(Qt.cyan)
示例3: _draw_polygon
def _draw_polygon(self, painter, xMap, yMap, range_tuple):
# range_tuple might contain more then four values !
rtmin, rtmax, mzmin, mzmax = range_tuple[:4]
points = QPolygonF()
points.append(QPointF(xMap.transform(rtmin), yMap.transform(mzmin)))
points.append(QPointF(xMap.transform(rtmin), yMap.transform(mzmax)))
points.append(QPointF(xMap.transform(rtmax), yMap.transform(mzmax)))
points.append(QPointF(xMap.transform(rtmax), yMap.transform(mzmin)))
painter.drawPolygon(points)
return points
示例4: _paintPolygon
def _paintPolygon(self, painter, polygon):
path = QPainterPath()
for line in polygon:
ring = QPolygonF()
for point in line:
cur = self.toCanvasCoordinates(point) - self.pos()
ring.append(cur)
ring.append(ring[0])
path.addPolygon(ring)
painter.drawPath(path)
示例5: __init__
def __init__(self, canvas, params={}):
'''
Constructor
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
:param params: A dictionary defining all the properties of the position marker
:type params: dictionary
'''
self.canvas = canvas
self.type = params.get('type', 'BOX').upper()
self.size = int(params.get('size', 16))
self.bounding = 1.414213562 * self.size
self.length = float(params.get('length', 98.0))
self.width = float(params.get('width', 17.0))
self.shape = params.get('shape', ((0.0, -0.5), (0.5, -0.3), (0.5, 0.5), (-0.5, 0.50), (-0.5, -0.3)))
s = (self.size - 1) / 2
self.paintShape = QPolygonF([QPointF(-s, -s), QPointF(s, -s), QPointF(s, s), QPointF(-s, s)])
self.color = self.getColor(params.get('color', 'black'))
self.fillColor = self.getColor(params.get('fillColor', 'lime'))
self.penWidth = int(params.get('penWidth', 1))
if self.type in ('CROSS', 'X'):
self.penWidth = 5
self.trackLen = int(params.get('trackLength', 100))
self.trackColor = self.getColor(params.get('trackColor', self.fillColor))
self.track = deque()
self.pos = None
self.heading = 0
super(PositionMarker, self).__init__(canvas)
self.setZValue(int(params.get('zValue', 100)))
self.distArea = QgsDistanceArea()
self.distArea.setEllipsoid(u'WGS84')
self.distArea.setEllipsoidalMode(True)
self.updateSize()
示例6: __init__
def __init__(self, parent, fromView, toView, distributedObjects):
""" Constructor
@param parent parent for the QGraphicsPolygonItem-Constructor
@param fromView datagraph.htmlvariableview.HtmlVariableView, starting point of the Pointer
@param toView datagraph.htmlvariableview.HtmlVariableView, end point of the Pointer
@param distributedObjects distributedobjects.DistributedObjects, the DistributedObjects-Instance
fromView and toView are QGraphicsWebViews
"""
QGraphicsLineItem.__init__(self, parent)
self.fromView = fromView
fromView.addOutgoingPointer(self)
self.toView = toView
toView.addIncomingPointer(self)
#self.setBrush( QBrush( self.bgcolor ) )
self.setPen(QPen(self.fgcolor, 1))
self.distributedObjects = distributedObjects
QObject.connect(self.fromView, SIGNAL('geometryChanged()'), self.updatePosition)
QObject.connect(self.toView, SIGNAL('geometryChanged()'), self.updatePosition)
QObject.connect(self.fromView, SIGNAL('xChanged()'), self.updatePosition)
QObject.connect(self.fromView, SIGNAL('yChanged()'), self.updatePosition)
QObject.connect(self.toView, SIGNAL('xChanged()'), self.updatePosition)
QObject.connect(self.toView, SIGNAL('yChanged()'), self.updatePosition)
QObject.connect(self.fromView, SIGNAL('removing()'), self.delete)
QObject.connect(self.toView, SIGNAL('removing()'), self.delete)
self.arrowhead = QPolygonF()
self.arrowSize = 20
self.setZValue(-1) # paint the arrows behind (lower z-value) everything else
示例7: __init__
def __init__(self, *args):
self.seleccionado = False
self.velocity = random.randint(1,10)
QGraphicsPixmapItem.__init__(self, *args)
self.setPixmap(QPixmap("sprites/"+str(random.randint(1,45))+".png"))
self.setTransformOriginPoint(self.boundingRect().width()/2.0,self.boundingRect().height()/2.0)
self.setZValue(10)
##menu contextual
self.menu = QMenu()
self.Actions =[] #arreglo de acciones
self.Actions.append( self.menu.addAction("Seguir") )
self.Actions.append( self.menu.addAction("Editar") )
self.Actions.append( self.menu.addAction("girar clockwise") )
self.Actions.append( self.menu.addAction("girar anti-clockwise") )
self.Actions.append( self.menu.addAction("Colisiones") )
self.Actions.append( self.menu.addAction("Duplicar") )
self.Actions.append( self.menu.addAction("Eliminar") )
self.menu.triggered[QAction].connect(self.test)
##offset para el arrastre
self.offset= QPointF(0,0)
##poligono de vision
poligono = QPolygonF()
poligono.append(QPointF(-1,10))
poligono.append(QPointF(-1,20))
poligono.append(QPointF(-30,40))
poligono.append(QPointF(-40,15))
poligono.append(QPointF(-30,-10))
self.vision = QGraphicsPolygonItem(poligono,self,self.scene())
self.vision.setBrush(QColor(255, 255, 0,100))
self.vision.setPen(QColor(255, 255, 0))
示例8: __updateShape
def __updateShape(self):
fBBox = QFontMetrics(self.Font).boundingRect(self.Name)
if self.__polygon.boundingRect().width() < fBBox.width():
self.__polygon = QPolygonF(QRectF(fBBox).normalized().adjusted(-fBBox.width() / 4,
-fBBox.height() / 4,
fBBox.height(),
fBBox.height() / 2))
示例9: sample_interpolate
def sample_interpolate(self, x, y):
spline = QwtSpline()
points = QPolygonF()
for point in zip(x, y):
points.append(QPointF(*point))
spline.setSplineType(QwtSpline.Natural)
spline.setPoints(points)
px = range(0, 2**12, DistanceIR.DIVIDER)
py = []
for X in px:
py.append(spline.value(X))
for i in range(x[0]/DistanceIR.DIVIDER):
py[i] = y[0]
for i in range(x[-1]/DistanceIR.DIVIDER, 2**12/DistanceIR.DIVIDER):
py[i] = y[-1]
for i in range(len(py)):
if py[i] > y[0]:
py[i] = y[0]
if py[i] < y[-1]:
py[i] = y[-1]
try:
old_text = self.sample_edit.text()
for i in range(DistanceIR.NUM_VALUES):
value = int(round(py[i]*100))
self.dist.set_sampling_point(i, value)
set_value = self.dist.get_sampling_point(i)
if set_value != value:
self.sample_edit.setText("Error while writing sample point " + str(i))
self.sample_edit.setText("writing sample point, value: " + str((i, value)))
QApplication.processEvents()
self.sample_edit.setText(old_text)
except ip_connection.Error:
return
示例10: on_actionGotoCell_triggered
def on_actionGotoCell_triggered(self):
cells = [str(cid) for cid in self._data.cells]
selected, ok = QInputDialog.getItem(self, "Goto cell", "Select the cell to go to", cells, 0)
if ok:
cid = int(selected)
self.ui.actionAdd_cell.setChecked(True)
data = self._data
if cid not in data.cells:
return
ls = data.cells_lifespan[cid]
prev_pos = self._previousScene.current_data._current_index
cur_pos = self._currentScene.current_data._current_index
full_poly = data.cells[cid]
poly = [pid for pid in full_poly if pid in data[prev_pos]]
#log_debug("Cell %d on time %d: %s" % (cid, prev_pos, poly))
if prev_pos < ls.start or prev_pos >= ls.end or not poly:
for i in range(*ls.slice().indices(len(data))):
poly = [pid for pid in full_poly if pid in data[i]]
if poly:
log_debug("Found cell %d on image %d with polygon %s" % (cid, i, poly))
new_prev_pos = i
break
else:
log_debug("Cell %d found nowhere in range %s!!!" % (cid, ls.slice()))
else:
new_prev_pos = prev_pos
new_cur_pos = min(max(cur_pos + new_prev_pos - prev_pos, 0), len(data))
self.ui.previousState.setCurrentIndex(new_prev_pos)
self.ui.currentState.setCurrentIndex(new_cur_pos)
self._previousScene.current_cell = cid
self._currentScene.current_cell = cid
prev_data = self._previousScene.current_data
poly = data.cells[cid]
prev_poly = QPolygonF([prev_data[ptid] for ptid in poly if ptid in prev_data])
prev_bbox = prev_poly.boundingRect()
log_debug("Previous bounding box = %dx%d+%d+%d" % (prev_bbox.width(), prev_bbox.height(),
prev_bbox.left(), prev_bbox.top()))
self.ui.previousData.ensureVisible(prev_bbox)
示例11: item
def item(self):
if self.item_ is None:
num_pts = len(self.pts_)
if num_pts == 1:
# draw a point
item = QGraphicsEllipseItem(self.pts_[0][0]-self.radius_,
self.pts_[0][1]-self.radius_,
2*self.radius_,
2*self.radius_)
item.setBrush(self.qcolor)
elif num_pts == 2:
item = QGraphicsLineItem(self.pts_[0][0], self.pts_[0][1],
self.pts_[1][0], self.pts_[1][1])
else:
poly = QPolygonF()
for p in self.pts_:
poly.append(QPointF(p[0],p[1]))
item = QGraphicsPolygonItem(poly)
item.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable)
item.setPen(self.qcolor)
item.setEnabled(True)
item.setActive(True)
self.item_ = item
return self.item_
示例12: __init__
def __init__(self, ENodeHandle):
ENode.__init__(self, ENodeHandle)
self.__polygon = QPolygonF(QRectF(-50, -15, 100, 30))
self.__updateShape()
self.__attributes = {}
self.__hiddenAttributes = {}
self.__group = QGraphicsItemGroup()
self.__group.addToGroup(QGraphicsPolygonItem(self.__polygon))
self.__buildAttributes(self.Handle.lsInputAttributes())
self.__buildAttributes(self.Handle.lsOutputAttributes(), True)
self.__muted = None
示例13: setSpinBoxDownIcon
def setSpinBoxDownIcon(self, opacity=0.6):
self.buttonStyle = "spinDown"
self.setToolTip("- 1")
pixmap = QPixmap(250, 250)
pixmap.fill(self.backgroundColor)
painter = QPainter()
painter.begin(pixmap)
painter.setRenderHint(QPainter.Antialiasing)
painter.setOpacity(opacity)
brush = QBrush(self.foregroundColor)
painter.setBrush(brush)
pen = QPen(self.foregroundColor)
painter.setPen(pen)
points = QPolygonF()
points.append(QPointF(125.0, 200.0))
points.append(QPointF(200.0, 70.0))
points.append(QPointF(50.0, 70.0))
painter.drawPolygon(points)
painter.end()
pixmap = pixmap.scaled(QSize(self.pixmapWidth, self.pixmapHeight),Qt.KeepAspectRatio, Qt.SmoothTransformation)
self.setPixmap(pixmap)
示例14: test_QPolygon_intersection
def test_QPolygon_intersection(self):
tri1 = QVectorF([(0,0),(0,1),(1,0)])
tri2 = QVectorF([(1,0),(0,0),(1,1)])
tri3 = QVectorF([(.5,.5),(1,0),(0,0),(.5,.5)])
tri3i = QVector([(1,1),(1,0),(0,0),(1,1)])
sq1 = QVectorF([(0,0),(0,1),(1,1),(1,0)])
# Intersect two triangles
p1 = QPolygonF(tri1)
p2 = QPolygonF(tri2)
p3 = p1.intersected(p2)
self.assertTrue( p1 == p1 )
self.assertTrue( p1 == QPolygonF(tri1) )
self.assertTrue( p3 == QPolygonF(tri3) )
# Intersect two integer triangles
p1 = QtGui.QPolygon(map(lambda (x,y): QtCore.QPoint(x,y), [(0,0),(0,1),(1,0)]))
p2 = QtGui.QPolygon(map(lambda (x,y): QtCore.QPoint(x,y), [(1,0),(0,0),(1,1)]))
p3 = p1.intersected(p2)
self.assertTrue( p3 == QtGui.QPolygon(tri3i) )
# Test containment/overlapping
p1 = QtGui.QPolygonF(sq1)
for v1 in sq1: self.assertTrue( p1.contains(v1) ) # vertices are contained
self.assertTrue( p1.translated(2,0).intersected(p1).isEmpty() )
self.assertTrue( p1.translated(1,0).intersected(p1).isEmpty() ) # common edges do not overlap
self.assertFalse( p1.translated(.5,0).intersected(p1).isEmpty() )
示例15: paintEvent
def paintEvent(self, event):
page_bottom = self.edit.viewport().height()
font_metrics = QFontMetrics(self.edit.document().defaultFont())
current_block = self.edit.document().findBlock(
self.edit.textCursor().position())
pattern = self.pat if self.edit.lang == "python" else self.patNotPython
painter = QPainter(self)
background = resources.CUSTOM_SCHEME.get('sidebar-background',
resources.COLOR_SCHEME['sidebar-background'])
foreground = resources.CUSTOM_SCHEME.get('sidebar-foreground',
resources.COLOR_SCHEME['sidebar-foreground'])
painter.fillRect(self.rect(), QColor(background))
block = self.edit.firstVisibleBlock()
viewport_offset = self.edit.contentOffset()
line_count = block.blockNumber()
painter.setFont(self.edit.document().defaultFont())
while block.isValid():
line_count += 1
# The top left position of the block in the document
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
# Set the Painter Pen depending on special lines
painter.setPen(QColor(foreground))
error = False
checkers = sorted(self._neditable.registered_checkers,
key=lambda x: x[2], reverse=True)
for items in checkers:
checker, color, _ = items
if (line_count - 1) in checker.checks:
painter.setPen(QColor(color))
font = painter.font()
font.setItalic(True)
font.setUnderline(True)
painter.setFont(font)
error = True
break
# We want the line number for the selected line to be bold.
bold = False
if block == current_block:
bold = True
font = painter.font()
font.setBold(True)
painter.setFont(font)
# Draw the line number right justified at the y position of the
# line. 3 is a magic padding number. drawText(x, y, text).
if block.isVisible():
painter.drawText(self.width() - self.foldArea -
font_metrics.width(str(line_count)) - 3,
round(position.y()) + font_metrics.ascent() +
font_metrics.descent() - 1,
str(line_count))
# 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()
#.........这里部分代码省略.........