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


Python QtCore.QPointF类代码示例

本文整理汇总了Python中PyQt5.QtCore.QPointF的典型用法代码示例。如果您正苦于以下问题:Python QPointF类的具体用法?Python QPointF怎么用?Python QPointF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: calcRowCol

    def calcRowCol(self, point: QPointF):
        """ Calculate the network row and column that a point is int
            calc the row and column indexes of a point

            The following is the algorithm:
            1.  Find the distance between the point and the left (or top)
            2.  Divide the distance with the width of path to find the relative position
            3.  Multipile this relative position with the number of rows/cols
            4.  Convert the result to int to find the indexes
            5.  If the index is the number of row/col reduce the index
                (This is for the case the the point is on the boundary and in this
                case the relative position is 1 which will cause the indexes to
                be the number of rows/cols - out of the matrix indexes)

            Args:
                point (QPointF) : The point to resolve

            Returns:
                int : The network row that the point is in
                int : The network column that the point is in  

        """
        partialX = (point.x() - self.charPath.boundingRect().left()) / self.charPath.boundingRect().width()
        partialY = (point.y() - self.charPath.boundingRect().top()) / self.charPath.boundingRect().height()
        col_idx = int(partialX * self.netCols)
        row_idx = int(partialY * self.netRows)
        if row_idx == self.netRows:
            row_idx -= 1
        if col_idx == self.netCols:
            col_idx -= 1
        return row_idx, col_idx
开发者ID:IlanHindy,项目名称:AI-Learn,代码行数:31,代码来源:CharacterIdentifier.py

示例2: image

    def image(cls, **kwargs):
        """
        Returns an image suitable for the palette.
        :rtype: QPixmap
        """
        # INITIALIZATION
        pixmap = QPixmap(kwargs['w'], kwargs['h'])
        pixmap.fill(Qt.transparent)
        painter = QPainter(pixmap)
        # INITIALIZE EDGE LINE
        pp1 = QPointF(((kwargs['w'] - 52) / 2), kwargs['h'] / 2)
        pp2 = QPointF(((kwargs['w'] - 52) / 2) + 52 - 2, kwargs['h'] / 2)
        line = QLineF(pp1, pp2)
        # CALCULATE HEAD COORDINATES
        angle = radians(line.angle())
        p1 = QPointF(line.p2().x() + 2, line.p2().y())
        p2 = p1 - QPointF(sin(angle + M_PI / 3.0) * 8, cos(angle + M_PI / 3.0) * 8)
        p3 = p1 - QPointF(sin(angle + M_PI - M_PI / 3.0) * 8, cos(angle + M_PI - M_PI / 3.0) * 8)
        # INITIALIZE EDGE HEAD
        head = QPolygonF([p1, p2, p3])
        # DRAW THE POLYGON
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(QPen(QColor(0, 0, 0), 1.1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(line)
        # DRAW HEAD
        painter.setPen(QPen(QColor(0, 0, 0), 1.1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.setBrush(QColor(0, 0, 0))
        painter.drawPolygon(head)
        # DRAW THE TEXT ON TOP OF THE EDGE
        space = 2 if Platform.identify() is Platform.Darwin else 0
        painter.setFont(Font('Arial', 9, Font.Light))
        painter.drawText(pp1.x() + space, (kwargs['h'] / 2) - 4, 'instanceOf')

        return pixmap
开发者ID:gitter-badger,项目名称:eddy,代码行数:34,代码来源:instance_of.py

示例3: render

  def render(self, widget):

    painter = widget.painter

    if not painter:
      return

    previousRenderHint = painter.renderHints()
    painter.setRenderHints(previousRenderHint | QPainter.Antialiasing)

    painter.setPen(Qt.NoPen)
    painter.setBrush(QColor(253, 242, 245))

    painter.drawEllipse(QRectF(self.pos - self.toPointF(self.size/2), self.size))

    mouseOffset = QPointF(widget.mousePosition) \
                  - self.pos \
                  - QPointF(widget.frameGeometry().topLeft())

    ox, oy = mouseOffset.x(), mouseOffset.y()
    distance = math.sqrt(ox**2 + oy**2)

    if distance > self.eyesight_radius:
      ox *= self.eyesight_radius / distance
      oy *= self.eyesight_radius / distance

    px = self.pos.x() + ox/self.eyesight_radius * (self.size-self.pupil_size).width() / 2
    py = self.pos.y() + oy/self.eyesight_radius * (self.size-self.pupil_size).height() / 2

    pos = QPointF(px, py)

    painter.setBrush(Qt.black)
    painter.drawEllipse(QRectF(pos - self.toPointF(self.pupil_size/2), self.pupil_size))

    painter.setRenderHints(previousRenderHint)
开发者ID:pvaret,项目名称:keyes,代码行数:35,代码来源:KEyes.py

示例4: __init__

 def __init__(self):
     super().__init__()
     self.MAR = 50
     self.points = []
     self.top_left = QPointF(float('Inf'), float('Inf'))
     self.bottom_right = QPointF(-float('Inf'), -float('Inf'))
     self.rect = QRectF()
开发者ID:bssthu,项目名称:L5MapEditor,代码行数:7,代码来源:polygon_base.py

示例5: mouseIsOnIO

    def mouseIsOnIO(self, mousePos, click = False):    	
    	#Returns the IO that the mouse is on
        for i in range(0, len(self.ioList)):
            #Adjust if IO is centered on a side
            if self.ioList[i][3] == 'left':
                yTranslation = self.yTranslationLeftIO
            else:
                yTranslation = self.yTranslationRightIO

            #Get point of IO
            IOPoint = QPointF(self.ioList[i][0], self.ioList[i][1] + yTranslation)

            #If mouse is over IO -> return IO
            if mousePos.x() > IOPoint.x() and mousePos.x() < IOPoint.x() + self.ioWidth:
                if mousePos.y() > IOPoint.y() and mousePos.y() < IOPoint.y() + self.ioHeight:
                    # entry point for drawing graphs.......
                    # if click:
                    #     print('mouse on IO: ' + str(i) + ' (' + str(self.ioList[i][3]) + ', ' + str(self.ioList[i][4]) + ')')
                    
                    #Update the hover paramater of the IO
                    self.ioList.insert(i, (self.ioList[i][0], self.ioList[i][1], self.ioList[i][2], self.ioList[i][3], self.ioList[i][4], True, self.ioList[i][6]))
                    del self.ioList[i + 1]

                    self.setFlag(QGraphicsItem.ItemIsSelectable, False)
                    self.setFlag(QGraphicsItem.ItemIsMovable, False)
                    self.hover = False
                    return i
        #If no IO is found under the mouse -> make sure hovering is enabled and return -1
        self.hover = True
        self.setHoveringToFalse()
        return -1
开发者ID:rinsewester,项目名称:SDFkit,代码行数:31,代码来源:node.py

示例6: applyLayerValue

    def applyLayerValue(self, id, val):
        layer = self.mObject
        layerIndex = self.mMapDocument.map().layers().indexOf(layer)
        command = None
        x = id
        if x==PropertyId.NameProperty:
            command = RenameLayer(self.mMapDocument, layerIndex, val)
        elif x==PropertyId.VisibleProperty:
            command = SetLayerVisible(self.mMapDocument, layerIndex, val)
        elif x==PropertyId.OpacityProperty:
            command = SetLayerOpacity(self.mMapDocument, layerIndex, val)
        elif x==PropertyId.OffsetXProperty or x==PropertyId.OffsetYProperty:
            offset = QPointF(layer.offset())

            if id == PropertyId.OffsetXProperty:
                offset.setX(val)
            else:
                offset.setY(val)

            command = SetLayerOffset(self.mMapDocument, layerIndex, offset)
        else:
            x = layer.layerType()
            if x==Layer.TileLayerType:
                self.applyTileLayerValue(id, val)
            elif x==Layer.ObjectGroupType:
                self.applyObjectGroupValue(id, val)
            elif x==Layer.ImageLayerType:
                self.applyImageLayerValue(id, val)
        if (command):
            self.mMapDocument.undoStack().push(command)
开发者ID:theall,项目名称:Python-Tiled,代码行数:30,代码来源:propertybrowser.py

示例7: _get_selected_edge

    def _get_selected_edge(self, pos: QPointF, transform: QTransform, horizontal_selection: bool):
        x1, x2 = self.x, self.x + self.width
        y1, y2 = self.y, self.y + self.height
        x, y = pos.x(), pos.y()

        spacing = 5
        spacing /= transform.m11() if horizontal_selection else transform.m22()

        if horizontal_selection:
            x1a, x1b = x1 - spacing, x1 + spacing
            y1a, y1b = y1, y2
            x2a, x2b = x2 - spacing, x2 + spacing
            y2a, y2b = y1, y2
        else:
            x1a, x1b, x2a, x2b = x1, x2, x1, x2
            y1a, y1b = min(y1 - spacing, y1 + spacing), max(y1 - spacing, y1 + spacing)
            y2a, y2b = min(y2 - spacing, y2 + spacing), max(y2 - spacing, y2 + spacing)

        if x1a < x < x1b and y1a < y < y1b:
            self.selected_edge = 0
            return 0

        if x2a < x < x2b and y2a < y < y2b:
            self.selected_edge = 1
            return 1

        self.selected_edge = None
        return None
开发者ID:jopohl,项目名称:urh,代码行数:28,代码来源:Selection.py

示例8: buildNodeFromShapeNode

    def buildNodeFromShapeNode(self, item, element):
        """
        Build a node using the given item type and QDomElement.
        :type item: Item
        :type element: QDomElement
        :rtype: AbstractNode
        """
        data = element.firstChildElement('data')
        while not data.isNull():

            if data.attribute('key', '') == self.keys['node_key']:

                shapeNode = data.firstChildElement('y:ShapeNode')
                geometry = shapeNode.firstChildElement('y:Geometry')

                kwargs = {
                    'id': element.attribute('id'),
                    'height': float(geometry.attribute('height')),
                    'width': float(geometry.attribute('width')),
                }

                node = self.factory.create(item, self.scene, **kwargs)
                # yEd uses the TOP-LEFT corner as (0,0) coordinate => we need to translate our
                # position (0,0), which is instead at the center of the shape, so that the TOP-LEFT
                # corner of the shape in yEd matches the TOP-LEFT corner of the shape in Eddy.
                # Additionally we force-snap the position to the grid so that items say aligned.
                pos = QPointF(float(geometry.attribute('x')), float(geometry.attribute('y')))
                pos = pos + QPointF(node.width() / 2, node.height() / 2)
                pos = QPointF(snapF(pos.x(), DiagramScene.GridSize), snapF(pos.y(), DiagramScene.GridSize))
                node.setPos(pos)
                return node

            data = data.nextSiblingElement('data')

        return None
开发者ID:gitter-badger,项目名称:eddy,代码行数:35,代码来源:graphml.py

示例9: update_bounding_rect

    def update_bounding_rect(self, pt):
        """插入新顶点时,更新 bounding rect

        Args:
            pt (QPointF): 新插入的顶点
        """
        self.top_left = QPointF(min(self.top_left.x(), pt.x()), min(self.top_left.y(), pt.y()))
        self.bottom_right = QPointF(max(self.bottom_right.x(), pt.x()), max(self.bottom_right.y(), pt.y()))
        self.rect = QRectF(self.top_left, self.bottom_right).adjusted(-self.MAR, -self.MAR, self.MAR, self.MAR)
        self.prepareGeometryChange()
开发者ID:bssthu,项目名称:L5MapEditor,代码行数:10,代码来源:polygon_base.py

示例10: is_in_roi

    def is_in_roi(self, pos: QPointF):
        x1 = self.rect().x()
        x2 = x1 + self.rect().width()
        y1 = self.rect().y()
        y2 = y1 + self.rect().width()

        if x1 < pos.x() < x2 and y1 < pos.y() < y2:
            return True

        return False
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:10,代码来源:ROI.py

示例11: QSizeF

class Eye:

  pupil_size      = QSizeF(5, 5)
  eyesight_radius = 100.0


  def __init__(self, x, y, w, h):

    ## x, y are the coordinates of the center of the eye.
    ## w, h are the total width and height of the eye.

    self.size = QSizeF(w, h)
    self.pos  = QPointF(x, y)


  def toPointF(self, size):

    return QPointF(size.width(), size.height())


  def render(self, widget):

    painter = widget.painter

    if not painter:
      return

    previousRenderHint = painter.renderHints()
    painter.setRenderHints(previousRenderHint | QPainter.Antialiasing)

    painter.setPen(Qt.NoPen)
    painter.setBrush(QColor(253, 242, 245))

    painter.drawEllipse(QRectF(self.pos - self.toPointF(self.size/2), self.size))

    mouseOffset = QPointF(widget.mousePosition) \
                  - self.pos \
                  - QPointF(widget.frameGeometry().topLeft())

    ox, oy = mouseOffset.x(), mouseOffset.y()
    distance = math.sqrt(ox**2 + oy**2)

    if distance > self.eyesight_radius:
      ox *= self.eyesight_radius / distance
      oy *= self.eyesight_radius / distance

    px = self.pos.x() + ox/self.eyesight_radius * (self.size-self.pupil_size).width() / 2
    py = self.pos.y() + oy/self.eyesight_radius * (self.size-self.pupil_size).height() / 2

    pos = QPointF(px, py)

    painter.setBrush(Qt.black)
    painter.drawEllipse(QRectF(pos - self.toPointF(self.pupil_size/2), self.pupil_size))

    painter.setRenderHints(previousRenderHint)
开发者ID:pvaret,项目名称:keyes,代码行数:55,代码来源:KEyes.py

示例12: moveUIPoint

def moveUIPoint(contour, point, delta):
    if point.segmentType is None:
        # point is an offCurve. Get its sibling onCurve and the other
        # offCurve.
        onCurve, otherPoint = _getOffCurveSiblingPoints(contour, point)
        # if the onCurve is selected, the offCurve will move along with it
        if onCurve.selected:
            return
        point.move(delta)
        if not onCurve.smooth:
            contour.dirty = True
            return
        # if the onCurve is smooth, we need to either...
        if otherPoint.segmentType is None and not otherPoint.selected:
            # keep the other offCurve inline
            line = QLineF(point.x, point.y, onCurve.x, onCurve.y)
            otherLine = QLineF(
                onCurve.x, onCurve.y, otherPoint.x, otherPoint.y)
            line.setLength(line.length() + otherLine.length())
            otherPoint.x = line.x2()
            otherPoint.y = line.y2()
        else:
            # keep point in tangency with onCurve -> otherPoint segment,
            # ie. do an orthogonal projection
            line = QLineF(otherPoint.x, otherPoint.y, onCurve.x, onCurve.y)
            n = line.normalVector()
            n.translate(QPointF(point.x, point.y) - n.p1())
            targetPoint = QPointF()
            n.intersect(line, targetPoint)
            # check that targetPoint is beyond its neighbor onCurve
            # we do this by calculating position of the offCurve and second
            # onCurve relative to the first onCurve. If there is no symmetry
            # in at least one of the axis, then we need to clamp
            onCurvePoint = line.p2()
            onDistance = line.p1() - onCurvePoint
            newDistance = targetPoint - onCurvePoint
            if (onDistance.x() >= 0) != (newDistance.x() <= 0) or \
                    (onDistance.y() >= 0) != (newDistance.y() <= 0):
                targetPoint = onCurvePoint
            # ok, now set pos
            point.x, point.y = targetPoint.x(), targetPoint.y()
    else:
        # point is an onCurve. Move its offCurves along with it.
        index = contour.index(point)
        point.move(delta)
        for d in (-1, 1):
            # edge-case: contour open, trailing offCurve and moving first
            # onCurve in contour
            if contour.open and index == 0 and d == -1:
                continue
            pt = contour.getPoint(index + d)
            if pt.segmentType is None:
                pt.move(delta)
    contour.dirty = True
开发者ID:bitforks,项目名称:trufont,代码行数:54,代码来源:uiMethods.py

示例13: getModelPos

    def getModelPos(self, pos: QPointF) -> Vec3T:
        """Y-axis is inverted in Qt +y === DOWN

        Args:
            pos: a position in this scene

        Returns:
            position in model coordinates
        """
        sf = self.scale_factor
        x, y = pos.x()/sf, -1.0*pos.y()/sf
        return x, y, 0.
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:12,代码来源:nucleicacidpartitem.py

示例14: helixIndex

    def helixIndex(self, point: QPointF) -> Vec2T:
        """Returns the (row, col) of the base which point lies within.

        Returns:
            point (tuple) in virtual_helix_item coordinates

        Args:
            point (TYPE): Description
        """
        x = int(int(point.x()) / _BW)
        y = int(int(point.y()) / _BW)
        return (x, y)
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:12,代码来源:abstractpathtool.py

示例15: __init__

    def __init__(self, sourceNode, destNode):
        super(Edge, self).__init__()

        self.arrowSize = 10.0
        self.sourcePoint = QPointF()
        self.destPoint = QPointF()

        self.setAcceptedMouseButtons(Qt.NoButton)
        self.source = sourceNode
        self.dest = destNode
        self.source.addEdge(self)
        self.dest.addEdge(self)
        self.adjust()
开发者ID:heylenz,项目名称:python27,代码行数:13,代码来源:elasticnodes.py


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