本文整理汇总了Python中PyQt4.QtGui.QGraphicsPolygonItem类的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsPolygonItem类的具体用法?Python QGraphicsPolygonItem怎么用?Python QGraphicsPolygonItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QGraphicsPolygonItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _finish_add_area
def _finish_add_area(self):
poligon = QPolygonF( self.current_op_stat['points'])
pol = QGraphicsPolygonItem(poligon)
pol.setToolTip(self.current_op_stat['name'])
pol.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
HMItem.type(pol,HMItem.MAP_AREA)
HMItem.select(pol,False)
HMItem.name(pol,self.current_op_stat['name'])
HMItem.level(pol, self.home_map_scene.current_level)
pol.setVisible(True)
pol.setZValue(1)
self.home_map_scene.addItem(pol)
print "flags %x" % pol.flags()
it_remove = QGraphicsPolygonItem()
HMItem.module( it_remove, self.__class__.__name__)
HMItem.type(it_remove,HMItem.OUTLINE_POINT)
self.home_map_scene.remove_by_item(it_remove)
self.current_op = ''
self.current_op_stat = None
示例2: __init__
def __init__(self, i, mu1, mu2, sigma1, sigma2, phi, color):
OWPlotItem.__init__(self)
self.outer_box = QGraphicsPolygonItem(self)
self.inner_box = QGraphicsPolygonItem(self)
self.i = i
self.mu1 = mu1
self.mu2 = mu2
self.sigma1 = sigma1
self.sigma2 = sigma2
self.phi = phi
self.twosigmapolygon = QPolygonF([
QPointF(i, mu1 - sigma1), QPointF(i, mu1 + sigma1),
QPointF(i + 1, mu2 + sigma2), QPointF(i + 1, mu2 - sigma2),
QPointF(i, mu1 - sigma1)
])
self.sigmapolygon = QPolygonF([
QPointF(i, mu1 - .5 * sigma1), QPointF(i, mu1 + .5 * sigma1),
QPointF(i + 1, mu2 + .5 * sigma2), QPointF(i + 1, mu2 - .5 * sigma2),
QPointF(i, mu1 - .5 * sigma1)
])
if isinstance(color, tuple):
color = QColor(*color)
color.setAlphaF(.3)
self.outer_box.setBrush(color)
self.outer_box.setPen(QColor(0, 0, 0, 0))
self.inner_box.setBrush(color)
self.inner_box.setPen(color)
示例3: __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
"""
QGraphicsPolygonItem.__init__(self, parent)
self.fromView = fromView
fromView.addOutgoingPointer(self)
self.toView = toView
toView.addIncomingPointer(self)
self.distributedObjects = distributedObjects
self.setBrush( QBrush( self.bgcolor ) )
self.setPen( QPen(self.fgcolor,1) )
QObject.connect(self.fromView, SIGNAL('geometryChanged()'), self.render)
QObject.connect(self.toView, SIGNAL('geometryChanged()'), self.render)
QObject.connect(self.fromView, SIGNAL('xChanged()'), self.render)
QObject.connect(self.fromView, SIGNAL('yChanged()'), self.render)
QObject.connect(self.toView, SIGNAL('xChanged()'), self.render)
QObject.connect(self.toView, SIGNAL('yChanged()'), self.render)
QObject.connect(self.fromView, SIGNAL('deleting()'), self.delete)
QObject.connect(self.toView, SIGNAL('deleting()'), self.delete)
self.render()
示例4: __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)
示例5: _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)
示例6: __init__
def __init__(self, poly = None, dim = None):
if not poly:
if not dim:
raise ValueError("need to set bounding rect!")
else:
poly = []
for i in range(10):
poly.append(planar.Point(
random.randint(dim.left(),dim.right()),
random.randint(dim.top(),dim.bottom())))
poly = planar.Polygon.convex_hull(poly)
poly = QPolygonF([QPointF(p.x,p.y) for p in poly])
QGraphicsPolygonItem.__init__(self, poly)
self.setConnectors([(0,random.random()),(len(poly)//2,random.random())])
示例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: paint
def paint(self, painter, option, widget = None):
QGraphicsPolygonItem.paint(self, painter, option, widget)
pen = QPen(QColor("yellow"))
pen.setWidth(10)
painter.setPen(pen)
painter.drawPoint(self.entrance())
pen.setColor(QColor("magenta"))
painter.setPen(pen)
painter.drawPoint(self.exit())
for c in self.connectors[2:]:
painter.drawPoint(c)
pen.setColor(QColor(0,255,255))
pen.setWidth(2)
painter.setPen(pen)
painter.drawEllipse(self.cog(), 5, 5)
示例9: PolygonCurve
class PolygonCurve(OWCurve):
"""
A plot item that shows a filled or empty polygon.
:param pen: The pen used to draw the polygon's outline
:type pen: :obj:`.QPen`
:param brush: The brush used to paint the polygon's inside
:type brush: :obj:`.QBrush`
:param xData: The list of x coordinates
:type xData: list of float
:param yData: The list of y coordinates
:type yData: list of float
:param tooltip: The tool tip shown when hovering over this curve
:type tooltip: str
"""
def __init__(self, pen=QPen(Qt.black), brush=QBrush(Qt.white), xData=[], yData=[], tooltip=None):
OWCurve.__init__(self, xData, yData, tooltip=tooltip)
self._data_polygon = self.polygon_from_data(xData, yData)
self._polygon_item = QGraphicsPolygonItem(self)
self.set_pen(pen)
self.set_brush(brush)
def update_properties(self):
self._polygon_item.setPolygon(self.graph_transform().map(self._data_polygon))
self._polygon_item.setPen(self.pen())
self._polygon_item.setBrush(self.brush())
@staticmethod
def polygon_from_data(xData, yData):
"""
Creates a polygon from a list of x and y coordinates.
:returns: A polygon with point corresponding to ``xData`` and ``yData``.
:rtype: QPolygonF
"""
if xData and yData:
n = min(len(xData), len(yData))
p = QPolygonF(n + 1)
for i in range(n):
p[i] = QPointF(xData[i], yData[i])
p[n] = QPointF(xData[0], yData[0])
return p
else:
return QPolygonF()
def set_data(self, xData, yData):
self._data_polygon = self.polygon_from_data(xData, yData)
OWCurve.set_data(self, xData, yData)
示例10: ParallelCoordinatePolygon
class ParallelCoordinatePolygon(OWPlotItem):
def __init__(self, i, mu1, mu2, sigma1, sigma2, phi, color):
OWPlotItem.__init__(self)
self.outer_box = QGraphicsPolygonItem(self)
self.inner_box = QGraphicsPolygonItem(self)
self.i = i
self.mu1 = mu1
self.mu2 = mu2
self.sigma1 = sigma1
self.sigma2 = sigma2
self.phi = phi
self.twosigmapolygon = QPolygonF([
QPointF(i, mu1 - sigma1), QPointF(i, mu1 + sigma1),
QPointF(i + 1, mu2 + sigma2), QPointF(i + 1, mu2 - sigma2),
QPointF(i, mu1 - sigma1)
])
self.sigmapolygon = QPolygonF([
QPointF(i, mu1 - .5 * sigma1), QPointF(i, mu1 + .5 * sigma1),
QPointF(i + 1, mu2 + .5 * sigma2), QPointF(i + 1, mu2 - .5 * sigma2),
QPointF(i, mu1 - .5 * sigma1)
])
if isinstance(color, tuple):
color = QColor(*color)
color.setAlphaF(.3)
self.outer_box.setBrush(color)
self.outer_box.setPen(QColor(0, 0, 0, 0))
self.inner_box.setBrush(color)
self.inner_box.setPen(color)
def update_properties(self):
self.outer_box.setPolygon(self.graph_transform().map(self.twosigmapolygon))
self.inner_box.setPolygon(self.graph_transform().map(self.sigmapolygon))
示例11: __init__
def __init__(self, pen=QPen(Qt.black), brush=QBrush(Qt.white), xData=[], yData=[], tooltip=None):
OWCurve.__init__(self, xData, yData, tooltip=tooltip)
self._data_polygon = self.polygon_from_data(xData, yData)
self._polygon_item = QGraphicsPolygonItem(self)
self.set_pen(pen)
self.set_brush(brush)
示例12: mouseDoubleClickEvent
def mouseDoubleClickEvent(self, mouseEvent):
QGraphicsPolygonItem.mouseDoubleClickEvent(self, mouseEvent)
self.toggleContentVisibility()
self.updateGeometry()
示例13: __init__
def __init__(self, world):
QGraphicsPolygonItem.__init__(self)
#############################
### Build graph
#############################
graph = pydot.Dot()
graph.set_node_defaults(color = 'red', fontcolor = 'red', label = '\<orphan\>')
graph.set('overlap', 'prism')
# build adjacency graph from world
for area in world.areas:
# create node for each room
node = pydot.Node(area.id)
node.set( 'label', area.name )
if area == world.player.currentArea:
node.set( 'color', 'blue' )
node.set( 'fontcolor', 'blue' )
else:
node.set( 'color', 'black' )
node.set( 'fontcolor', 'black' )
graph.add_node(node)
# link to adjacent rooms
for feature in area.features:
for action in feature.actions:
finalEvent = None
for event in action.events:
if type(event) == events.PlayerMoveEvent:
finalEvent = pydot.Edge( src=area.id, dst=event.properties['destination'] )
if finalEvent is not None:
graph.add_edge( finalEvent )
################################
### Generate SVG from graph
################################
ps = graph.create_svg(prog='neato')
#########################################
### Build graphics items from SVG
#########################################
# build xml tree
ns = {'svg': 'http://www.w3.org/2000/svg'}
doc = ET.fromstring(ps)
# grab the root node properties
rootNode = doc.xpath('/svg:svg/svg:g[1]', namespaces=ns)[0]
polygon = rootNode.xpath('./svg:polygon', namespaces=ns)[0]
pointStr = polygon.xpath('./@points', namespaces=ns)[0]
penColor = QString(polygon.xpath('./@stroke', namespaces=ns)[0])
fillColor = QString(polygon.xpath('./@fill', namespaces=ns)[0])
# parse root polygon path
path = QPolygonF()
for pair in pointStr.split(' '):
dims = pair.split(',')
point = QPointF( float(dims[0]), float(dims[1]) )
path.append(point)
self.setPolygon(path)
# fill in root node colors
if QColor.isValidColor(penColor):
self.setPen( QColor(penColor) )
if QColor.isValidColor(fillColor):
self.setBrush( QColor(fillColor) )
# build each graph node
for xmlNode in rootNode.xpath('./svg:g', namespaces=ns):
group = QGraphicsRectItem(self)
group.setPen( Qt.transparent )
group.setBrush( Qt.transparent )
if xmlNode.attrib['class'] == 'node':
# find the area object
name = xmlNode.xpath('./svg:title', namespaces=ns)[0].text
group.setData( 0, QString(world.areas[world.areaLookup[name]].id) )
# get the ellipse info
ellipseNode = xmlNode.xpath('./svg:ellipse', namespaces=ns)[0]
elProps = { k: float(ellipseNode.attrib[k]) for k in ['cx', 'cy', 'rx', 'ry']}
rect = QRectF( elProps['cx']-elProps['rx'], elProps['cy']-elProps['ry'], 2*elProps['rx'], 2*elProps['ry'])
penColor = QString(ellipseNode.attrib['stroke'])
ellipseItem = QGraphicsEllipseItem(rect, group)
if QColor.isValidColor(penColor):
ellipseItem.setPen( QColor(penColor) )
# get the text info
textNode = xmlNode.xpath('./svg:text', namespaces=ns)[0]
text = textNode.text
textItem = QGraphicsTextItem(text, group)
#.........这里部分代码省略.........
示例14: hoverLeaveEvent
def hoverLeaveEvent(self, mouseEvent):
QGraphicsPolygonItem.hoverLeaveEvent(self, mouseEvent)
self.toggleHighlight()
示例15: auto
class auto(QGraphicsPixmapItem):
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))
def info(self):
return "Velocidad "+ str(self.velocity)+" posicion "+ str(self.pos())[20:]+"\n"
def test(self,act):
print act.text()
if act.text()=="girar clockwise":
self.setRotation(self.rotation()-45)
if act.text()=="girar anti-clockwise":
self.setRotation(self.rotation()+45)
if act.text()=="Colisiones":
print "colisiones con",self.collidingItems(1),self.vision.collidingItems(1)
if act.text()=="Duplicar":
self.scene().addItem(auto())
if act.text()=="Eliminar":
self.scene().removeItem(self)
def contextMenuEvent(self,event):
self.menu.popup(event.screenPos())
def mousePressEvent(self, event):
p = event.pos()
self.offset= QPointF(p.x()*1.0,p.y()*1.0)
self.seleccionado = not self.seleccionado
def mouseMoveEvent(self, event):
self.setPos(event.scenePos()-self.offset)
def avanza(self):
if self.velocity !=0:
"""print velocity
print "current pos (%f,%f)"%(self.pos().x(),self.pos().y())
print "angle %f "%(self.rotation())"""
radians = self.rotation()*0.0174532925
""" print "angle rad %f "%(radians)"""
nx = 1.0*self.velocity*cos(radians)
ny = 1.0*self.velocity*sin(radians)
""" print "avanzara a (%f,%f)"%(nx,ny) """
self.setPos(self.pos().x()-nx,self.pos().y()-ny)
"""for i in self.collidingItems():