本文整理汇总了Python中PyQt5.QtCore.QPointF.x方法的典型用法代码示例。如果您正苦于以下问题:Python QPointF.x方法的具体用法?Python QPointF.x怎么用?Python QPointF.x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QPointF
的用法示例。
在下文中一共展示了QPointF.x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouseIsOnIO
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
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
示例2: __calculateEndingPoints_topToBottom
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
def __calculateEndingPoints_topToBottom(self):
"""
Private method to calculate the ending points of the association item.
The ending points are calculated from the top center of the lower item
to the bottom center of the upper item.
"""
if self.itemA is None or self.itemB is None:
return
self.prepareGeometryChange()
rectA = self.__mapRectFromItem(self.itemA)
rectB = self.__mapRectFromItem(self.itemB)
midA = QPointF(rectA.x() + rectA.width() / 2.0,
rectA.y() + rectA.height() / 2.0)
midB = QPointF(rectB.x() + rectB.width() / 2.0,
rectB.y() + rectB.height() / 2.0)
if midA.y() > midB.y():
startP = QPointF(rectA.x() + rectA.width() / 2.0, rectA.y())
endP = QPointF(rectB.x() + rectB.width() / 2.0,
rectB.y() + rectB.height())
else:
startP = QPointF(rectA.x() + rectA.width() / 2.0,
rectA.y() + rectA.height())
endP = QPointF(rectB.x() + rectB.width() / 2.0, rectB.y())
self.setPoints(startP.x(), startP.y(), endP.x(), endP.y())
示例3: buildEdgeFromGenericEdge
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
def buildEdgeFromGenericEdge(self, item, element):
"""
Build an edge using the given item type and QDomElement.
:type item: Item
:type element: QDomElement
:rtype: AbstractEdge
"""
data = element.firstChildElement('data')
while not data.isNull():
if data.attribute('key', '') == self.keys['edge_key']:
points = []
polyLineEdge = data.firstChildElement('y:PolyLineEdge')
path = polyLineEdge.firstChildElement('y:Path')
collection = path.elementsByTagName('y:Point')
for i in range(0, collection.count()):
point = collection.at(i).toElement()
pos = QPointF(float(point.attribute('x')), float(point.attribute('y')))
pos = QPointF(snapF(pos.x(), DiagramScene.GridSize), snapF(pos.y(), DiagramScene.GridSize))
points.append(pos)
kwargs = {
'id': element.attribute('id'),
'source': self.scene.node(element.attribute('source')),
'target': self.scene.node(element.attribute('target')),
'breakpoints': points,
}
edge = self.factory.create(item, self.scene, **kwargs)
# yEd, differently from the node pos whose origin matches the TOP-LEFT corner,
# consider the center of the shape as original anchor point (0,0). So if the
# anchor point hs a negative X it's moved a bit on the left with respect to
# the center of the shape (the same applies for the Y axis)
sourceP = QPointF(float(path.attribute('sx')), float(path.attribute('sy')))
sourceP = edge.source.pos() + sourceP
sourceP = QPointF(snapF(sourceP.x(), DiagramScene.GridSize), snapF(sourceP.y(), DiagramScene.GridSize))
targetP = QPointF(float(path.attribute('tx')), float(path.attribute('ty')))
targetP = edge.target.pos() + targetP
targetP = QPointF(snapF(targetP.x(), DiagramScene.GridSize), snapF(targetP.y(), DiagramScene.GridSize))
painterPath = edge.source.painterPath()
if painterPath.contains(edge.source.mapFromScene(sourceP)):
edge.source.setAnchor(edge, sourceP)
painterPath = edge.target.painterPath()
if painterPath.contains(edge.target.mapFromScene(targetP)):
edge.target.setAnchor(edge, targetP)
edge.source.addEdge(edge)
edge.target.addEdge(edge)
return edge
data = data.nextSiblingElement('data')
return None
示例4: PolygonBase
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
class PolygonBase(QGraphicsWidget):
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()
def boundingRect(self):
return self.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()
def move_bounding_rect(self, offset):
"""移动多边形时,更新 bounding rect
Args:
offset (QPointF): 平移向量
"""
self.top_left += offset
self.bottom_right += offset
self.rect.adjust(offset.x(), offset.y(), offset.x(), offset.y())
self.prepareGeometryChange()
def get_points(self):
"""获取多边形中的顶点列表
Returns:
points (list[QPointF]): 顶点列表
"""
return self.points
def get_vertices(self):
"""获取多边形中的顶点列表
Returns:
vertices (list[list[float]]): 顶点列表
"""
vertices = [[vertex.x(), vertex.y()] for vertex in self.points]
return vertices
示例5: mouseMovedWhileCreatingObject
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
def mouseMovedWhileCreatingObject(self, pos, modifiers):
renderer = self.mapDocument().renderer()
pixelCoords = renderer.screenToPixelCoords_(pos)
# Update the size of the new map object
objectPos = self.mNewMapObjectItem.mapObject().position()
newSize = QPointF(max(0.0, pixelCoords.x() - objectPos.x()),
max(0.0, pixelCoords.y() - objectPos.y()))
# Holding shift creates circle or square
if (modifiers & Qt.ShiftModifier):
m = max(newSize.x(), newSize.y())
newSize.setX(m)
newSize.setY(m)
SnapHelper(renderer, modifiers).snap(newSize)
self.mNewMapObjectItem.resizeObject(QSizeF(newSize.x(), newSize.y()))
示例6: calcRowCol
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
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
示例7: render
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
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)
示例8: image
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
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
示例9: buildNodeFromShapeNode
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
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
示例10: _get_selected_edge
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
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
示例11: getX
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
def getX(self, pos: QPointF) -> float:
"""
Args:
pos: Description
Returns:
``x`` position
"""
return pos.x()
示例12: getLargerEdgePath
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
def getLargerEdgePath(self):
#Used to fill in the small areas on the edge
#This makes it easier to select the edge
yTranslation = 2
#Curve 1
beginPoint = QPointF(self.beginPoint.x(), self.beginPoint.y() + yTranslation)
curvePoint1 = QPointF(self.curvePoint1.x()+4, self.curvePoint1.y() + yTranslation)
curvePoint2 = QPointF(self.curvePoint2.x()+4, self.curvePoint2.y() + yTranslation)
endPoint = QPointF(self.endPoint.x(), self.endPoint.y() + yTranslation)
path = QPainterPath(beginPoint)
point1 = QPointF(curvePoint1.x(), curvePoint1.y())
point2 = QPointF(curvePoint2.x(), curvePoint2.y())
path.cubicTo(point1, point2, endPoint)
#Arrow
arrowBeginPoint = QPointF(self.endPoint.x(), self.endPoint.y() + 4)
path.lineTo(arrowBeginPoint)
if self.endSide == 'right':
path.lineTo(QPointF(self.endPoint.x() - 10, self.endPoint.y()))
else:
path.lineTo(QPointF(self.endPoint.x() + 10, self.endPoint.y()))
path.lineTo(QPointF(self.endPoint.x(), self.endPoint.y() - 4))
path.lineTo(QPointF(self.endPoint.x(), self.endPoint.y() - 2))
#Curve 2 (back)
endPoint = QPointF(self.beginPoint.x(), self.beginPoint.y() - yTranslation)
curvePoint2 = QPointF(self.curvePoint1.x(), self.curvePoint1.y() - yTranslation)
curvePoint1 = QPointF(self.curvePoint2.x(), self.curvePoint2.y() - yTranslation)
beginPoint = QPointF(self.endPoint.x(), self.endPoint.y() - yTranslation)
point1 = QPointF(curvePoint1.x(), curvePoint1.y())
point2 = QPointF(curvePoint2.x(), curvePoint2.y())
path.cubicTo(point1, point2, endPoint)
if self.beginSide == 'right':
path.lineTo(QPointF(self.beginPoint.x() - 10, self.beginPoint.y() - 2))
path.lineTo(QPointF(self.beginPoint.x() - 10, self.beginPoint.y() + 2))
else:
path.lineTo(QPointF(self.beginPoint.x() + 10, self.beginPoint.y() - 2))
path.lineTo(QPointF(self.beginPoint.x() + 10, self.beginPoint.y() + 2))
path.lineTo(QPointF(self.beginPoint.x(), self.beginPoint.y() + 2))
return path
示例13: is_in_roi
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
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
示例14: QSizeF
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
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)
示例15: moveUIPoint
# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import x [as 别名]
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