当前位置: 首页>>代码示例>>Python>>正文


Python QGraphicsPolygonItem.setBrush方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QGraphicsPolygonItem.setBrush方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsPolygonItem.setBrush方法的具体用法?Python QGraphicsPolygonItem.setBrush怎么用?Python QGraphicsPolygonItem.setBrush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QGraphicsPolygonItem的用法示例。


在下文中一共展示了QGraphicsPolygonItem.setBrush方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PolygonCurve

# 需要导入模块: from PyQt4.QtGui import QGraphicsPolygonItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPolygonItem import setBrush [as 别名]
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)
开发者ID:kereturn,项目名称:orange3,代码行数:55,代码来源:owtools.py

示例2: ParallelCoordinatePolygon

# 需要导入模块: from PyQt4.QtGui import QGraphicsPolygonItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPolygonItem import setBrush [as 别名]
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))
开发者ID:r0k3,项目名称:orange3,代码行数:38,代码来源:owparallelgraph.py

示例3: __init__

# 需要导入模块: from PyQt4.QtGui import QGraphicsPolygonItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPolygonItem import setBrush [as 别名]
	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)
#.........这里部分代码省略.........
开发者ID:stevenvergenz,项目名称:pyVenture,代码行数:103,代码来源:svgsubitem.py

示例4: auto

# 需要导入模块: from PyQt4.QtGui import QGraphicsPolygonItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsPolygonItem import setBrush [as 别名]
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():
开发者ID:nicoyanez,项目名称:integracion4,代码行数:67,代码来源:auto.py


注:本文中的PyQt4.QtGui.QGraphicsPolygonItem.setBrush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。