Python PyQt4.QtGui 模块,QPolygonF() 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用PyQt4.QtGui.QPolygonF()

项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def setPolygon(self):
        '''Calculate position and rotation of the arc arrow head.'''
        rotDeg = 0            
        xlength = self.pos1.x() - self.pos2.x()
        ylength = self.pos1.y() - self.pos2.y()
        d = math.sqrt( math.pow( xlength , 2) + math.pow( ylength , 2) )        
        if d > 0:
            beta = math.acos( xlength / d )
            rotDeg = math.degrees( beta ) 

        self.arrowPolygonObject.setPolygon( QtGui.QPolygonF( [
                                                 QtCore.QPointF( (self.pos2.x() -10),  (self.pos2.y() +5)), 
                                                 QtCore.QPointF( (self.pos2.x() -10) , (self.pos2.y() -5)), 
                                                 QtCore.QPointF(       self.pos2.x() ,      self.pos2.y())
                                                 ] ) ) 

        self.arrowPolygonObject.setBrush( QtGui.QBrush(QtCore.Qt.black) )

        """ self.angle()!!!!!!!!!"""
#         self.arcLinePolygon.angle()
#         self.arcLinePolygon.rotate(rotDeg)
#         self.arcLinePolygon.setPos( self.pos2 ) 

    #------------------------------------------------------------------------------------------------
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def setPolygon(self):
        rotDeg = 0            
        xlength = self.pos1.x() - self.pos2.x()
        ylength = self.pos1.y() - self.pos2.y()
        d = math.sqrt( math.pow( xlength , 2) + math.pow( ylength , 2) )        
        if d > 0:
            beta = math.acos( xlength / d )
            rotDeg = math.degrees( beta ) 

        self.arcLinePolygon.setPolygon( QtGui.QPolygonF( [
                                                 QtCore.QPointF( (self.pos2.x() -10),  (self.pos2.y() +5)), 
                                                 QtCore.QPointF( (self.pos2.x() -10) , (self.pos2.y() -5)), 
                                                 QtCore.QPointF(       self.pos2.x() ,      self.pos2.y())
                                                 ] ) ) 

        self.arcLinePolygon.setBrush( QtGui.QBrush(QtCore.Qt.black) )

        """ self.angle()!!!!!!!!!"""
#         self.arcLinePolygon.angle()
#         self.arcLinePolygon.rotate(rotDeg)
#         self.arcLinePolygon.setPos( self.pos2 ) 
    #------------------------------------------------------------------------------------------------
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, startp=Point(), endp=None,
                 length=60.0, angle=50.0,
                 color=QtCore.Qt.red, pencolor=QtCore.Qt.green,
                 startarrow=True):
        """
        Initialisation of the class.
        """
        self.sc = None
        super(Arrow, self).__init__()

        self.startp = QtCore.QPointF(startp.x, -startp.y)
        self.endp = endp

        self.length = length
        self.angle = angle
        self.startarrow = startarrow
        self.allwaysshow = False

        self.arrowHead = QPolygonF()
        self.setFlag(QGraphicsItem.ItemIsSelectable, False)
        self.myColor = color
        self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
        self.pen.setCosmetic(True)
        self.arrowSize = 8.0
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def __init__(self, parent=None, scene=None):
        super(ArcItem, self).__init__(None)
        self.scene = scene
        self.parent = parent
        self.arcLine = LineItem(self)
        self.parent.diagramScene.addItem(self.arcLine)  
        arrowPolygon = QtGui.QPolygonF( [ 
                                         QtCore.QPointF(  0.0,  0.0),
                                         QtCore.QPointF(  0.0, 10.0), 
                                         QtCore.QPointF( 10.0,  5.0)
                                         ] )
        self.arcLinePolygon = self.parent.diagramScene.addPolygon( arrowPolygon ) 
        self.pos1 = QtCore.QPointF(20,20)
        self.pos2 = QtCore.QPointF(200,200)
#         self.setFlags( self.ItemIsSelectable | self.ItemIsMoveable )
项目:rec-attend-public    作者:renmengye    | 项目源码 | 文件源码
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore
项目:cityscapes-api    作者:renmengye    | 项目源码 | 文件源码
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, startItem, endItem, parent=None, scene=None):
        super(Arrow, self).__init__(parent, scene)

        self.arrowHead = QtGui.QPolygonF()

        self.myStartItem = startItem
        self.myEndItem = endItem
        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, True)
        self.myColor = QtCore.Qt.black
        self.setPen(QtGui.QPen(self.myColor, 2, QtCore.Qt.SolidLine,
                QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, diagramType, contextMenu, parent=None, scene=None):
        super(DiagramItem, self).__init__(parent, scene)

        self.arrows = []

        self.diagramType = diagramType
        self.contextMenu = contextMenu

        path = QtGui.QPainterPath()
        if self.diagramType == self.StartEnd:
            path.moveTo(200, 50)
            path.arcTo(150, 0, 50, 50, 0, 90)
            path.arcTo(50, 0, 50, 50, 90, 90)
            path.arcTo(50, 50, 50, 50, 180, 90)
            path.arcTo(150, 50, 50, 50, 270, 90)
            path.lineTo(200, 25)
            self.myPolygon = path.toFillPolygon()
        elif self.diagramType == self.Conditional:
            self.myPolygon = QtGui.QPolygonF([
                    QtCore.QPointF(-100, 0), QtCore.QPointF(0, 100),
                    QtCore.QPointF(100, 0), QtCore.QPointF(0, -100),
                    QtCore.QPointF(-100, 0)])
        elif self.diagramType == self.Step:
            self.myPolygon = QtGui.QPolygonF([
                    QtCore.QPointF(-100, -100), QtCore.QPointF(100, -100),
                    QtCore.QPointF(100, 100), QtCore.QPointF(-100, 100),
                    QtCore.QPointF(-100, -100)])
        else:
            self.myPolygon = QtGui.QPolygonF([
                    QtCore.QPointF(-120, -80), QtCore.QPointF(-70, 80),
                    QtCore.QPointF(120, 80), QtCore.QPointF(70, -80),
                    QtCore.QPointF(-120, -80)])

        self.setPolygon(self.myPolygon)
        self.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, True)
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
def clearPolygon(self):
        # We do not clear, since the drawPoly might be a reference on an object one
        self.drawPoly = QtGui.QPolygonF()
        self.drawPolyClosed = False
        # Disable actions that need a polygon
        for act in self.actPolyOrSelObj:
            act.setEnabled(bool(self.selObjs))
        for act in self.actClosedPoly:
            act.setEnabled(False)

    # We just closed the polygon and need to deal with this situation
项目:picasso    作者:jungmannlab    | 项目源码 | 文件源码
def __init__(self,  y,  x):
        hex_center_x,  hex_center_y = indextoHex(y, x)
        center = QtCore.QPointF(hex_center_x,  hex_center_y)
        points = [HEX_SCALE*HEX_SIDE_HALF * QtCore.QPointF(-1,  0) + center,
                  HEX_SCALE*HEX_SIDE_HALF * QtCore.QPointF(-0.5, sqrt(3)/2) + center,
                  HEX_SCALE*HEX_SIDE_HALF * QtCore.QPointF(0.5, sqrt(3)/2) + center,
                  HEX_SCALE*HEX_SIDE_HALF * QtCore.QPointF(1, 0) + center,
                  HEX_SCALE*HEX_SIDE_HALF * QtCore.QPointF(0.5, -sqrt(3)/2) + center,
                  HEX_SCALE*HEX_SIDE_HALF * QtCore.QPointF(-0.5, -sqrt(3)/2) + center]

        hexagonPointsF = QtGui.QPolygonF(points)
        super().__init__(hexagonPointsF)
        self.setPen(HEX_PEN)
        self.setBrush(defaultcolor)  # initialize all as grey
项目:BTCeTrader    作者:ch3ll0v3k    | 项目源码 | 文件源码
def poly(self, _pts):

        # -------------------------------------------------------------------
        """ Clean up if needet
        for x in xrange(0, len(_pts)):
            if self._CANDELS[x][0] == None:
                self._CANDELS[x][0] = 0;
            if self._CANDELS[x][1] == None:
                self._CANDELS[x][1] = 0;
        """

        return QPolygonF(map(lambda p: QPointF(*p), _pts))
        # -------------------------------------------------------------------

    # =======================================================================
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def __init__(self, editor, srcConnector, dstConnector, name="undefined", isPortConnection=False):
        '''

        :param editor: `gui.DiagramEditor`. Editor to show in.
        :param srcConnector: Source `model.AbstractItem.Connector`.
        :param dstConnector: Destination `model.AbstractItem.Connector`.
        :param name: Expression of the CPN arc assigned by the user. 
        :param isPortConnection: Flag that determines, whether the arc represents the connection between a substitution transition and a port place..
        '''
        QtGui.QGraphicsItem.__init__(self, None)
        self.editor = editor
        self.srcConnector = srcConnector
        self.dstConnector = dstConnector 
        self.isPortConnection = isPortConnection
        self.name = ""
        self.arcDefined = False
        self.variable = None
        self.expression = None
        self.diag = None        
        self.pos1 = None
        self.pos2 = None
        self.arrowPolygon = None
        self.replaceExpression = None
#         self.subnet = subnet
        self.setZValue(12)

        if self.srcConnector:            
            rect = self.srcConnector.rect()
            pos = self.mapFromItem( self.srcConnector, self.srcConnector.position )
            self.pos1 = QtCore.QPointF(pos.x() + rect.width()/2, pos.y() + rect.height()/2  )
            self.srcConnector.posCallbacks.append(self.setBeginPos)
            self.srcConnector.connectionArc = self

        self.arcLine = LineItem(self)
        self.editor.diagramScene.addItem(self.arcLine)  
        self.arrowPolygon = QtGui.QPolygonF( [ 
                                         QtCore.QPointF(  0.0,  0.0),
                                         QtCore.QPointF(  0.0, 10.0), 
                                         QtCore.QPointF( 10.0,  5.0)
                                         ] )
        self.arrowPolygonObject = self.editor.diagramScene.addPolygon( self.arrowPolygon )  
        self.label = QtGui.QGraphicsTextItem(name, self)
        self.label.setFlags(self.ItemIsSelectable | self.ItemIsMovable)
        self.editor.diagramScene.addItem(self.label)   

    #------------------------------------------------------------------------------------------------
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
def drawZoom(self,qp,overlay):
        # Zoom disabled?
        if not self.config.zoom:
            return
        # No image
        if self.image.isNull() or not self.w or not self.h:
            return
        # No mouse
        if not self.mousePos:
            return

        # Abbrevation for the zoom window size
        zoomSize = self.config.zoomSize
        # Abbrevation for the mouse position
        mouse = self.mousePos

        # The pixel that is the zoom center
        pix = self.mousePosScaled
        # The size of the part of the image that is drawn in the zoom window
        selSize = zoomSize / ( self.config.zoomFactor * self.config.zoomFactor )
        # The selection window for the image
        sel  = QtCore.QRectF(pix.x()  -selSize/2 ,pix.y()  -selSize/2 ,selSize,selSize  )
        # The selection window for the widget
        view = QtCore.QRectF(mouse.x()-zoomSize/2,mouse.y()-zoomSize/2,zoomSize,zoomSize)

        # Show the zoom image
        qp.drawImage(view,self.image,sel)

        # If we are currently drawing the polygon, we need to draw again in the zoom
        if not self.drawPoly.isEmpty():
            transform = QtGui.QTransform()
            quadFrom = QtGui.QPolygonF()
            quadFrom.append( sel.topLeft() )
            quadFrom.append( sel.topRight() )
            quadFrom.append( sel.bottomRight() )
            quadFrom.append( sel.bottomLeft() )
            quadTo = QtGui.QPolygonF()
            quadTo.append( view.topLeft() )
            quadTo.append( view.topRight() )
            quadTo.append( view.bottomRight() )
            quadTo.append( view.bottomLeft() )
            if QtGui.QTransform.quadToQuad( quadFrom , quadTo , transform ):
                qp.setClipRect(view)
                #transform.translate(self.xoff,self.yoff)
                self.drawDrawPoly(qp,transform)
            else:
                print( "not possible" )


    #############################
    ## Mouse/keyboard events
    #############################

    # Mouse moved
    # Need to save the mouse position
    # Need to drag a polygon point
    # Need to update the mouse selected object