本文整理匯總了Python中PyQt5.QtCore.QPointF方法的典型用法代碼示例。如果您正苦於以下問題:Python QtCore.QPointF方法的具體用法?Python QtCore.QPointF怎麽用?Python QtCore.QPointF使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtCore
的用法示例。
在下文中一共展示了QtCore.QPointF方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_polygons
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def add_polygons(self, polygons, color = '#A8F22A', alpha = 1):
qcolor = QColor()
qcolor.setNamedColor(color)
qcolor.setAlphaF(alpha)
for points in polygons:
qpoly = QPolygonF( [QPointF(p[0], p[1]) for p in points] )
scene_poly = self.scene.addPolygon(qpoly)
scene_poly.setBrush(qcolor)
scene_poly.setPen(self.pen)
self.scene_polys.append(scene_poly)
# Update custom bounding box
sr = scene_poly.sceneBoundingRect()
if len(self.scene_polys) == 1:
self.scene_xmin = sr.left()
self.scene_xmax = sr.right()
self.scene_ymin = sr.top()
self.scene_ymax = sr.bottom()
else:
self.scene_xmin = min(self.scene_xmin, sr.left())
self.scene_xmax = max(self.scene_xmax, sr.right())
self.scene_ymin = min(self.scene_ymin, sr.top())
self.scene_ymax = max(self.scene_ymax, sr.bottom())
示例2: transfer
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def transfer():
global epi_x, epi_y, p1, p2, p3, p4, rect
write_log()
dx = window.spin_trans_x.value()
dy = window.spin_trans_y.value()
scene.clear()
p1 = [p1[0] + dx, p1[1] + dy]
p2 = [p2[0] + dx, p2[1] + dy]
p3 = [p3[0] + dx, p3[1] + dy]
p4 = [p4[0] + dx, p4[1] + dy]
rect[0] = QPointF(p1[0], p1[1])
rect[1] = QPointF(p2[0], p2[1])
rect[2] = QPointF(p3[0], p3[1])
rect[3] = QPointF(p4[0], p4[1])
scene.addPolygon(rect, pen=p, brush=b)
epi_x = [x + dx for x in epi_x]
epi_y = [y + dy for y in epi_y]
l = len(epi_x)
for i in range(l):
scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p)
示例3: set
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def set():
global epi_x, epi_y, p1, p2, p3, p4, rect
scene.clear()
dx = 500
dy = 500
kx = 10
ky = 10
p1 = [-10 * kx + dx, -10 * ky + dy]
p2 = [-10 * kx + dx + 20 * kx, -10 * ky + dy]
p3 = [-10 * kx + dx + 20 * kx, -10 * ky + dy + 20 * ky]
p4 = [-10 * kx + dx, -10 * ky + dy + 20 * ky]
rect[0] = QPointF(p1[0], p1[1])
rect[1] = QPointF(p2[0], p2[1])
rect[2] = QPointF(p3[0], p3[1])
rect[3] = QPointF(p4[0], p4[1])
epi_x = []
epi_y = []
scene.addPolygon(rect, pen=p, brush=b)
for t in np.arange(0, 4 * math.pi, 0.001):
x = 5 * math.cos(t) * kx - 2 * math.cos(5 / 2 * t) * kx + dx
y = 5 * math.sin(t) * ky - 2 * math.sin(5 / 2 * t) * ky + dy
epi_x.append(x)
epi_y.append(y)
scene.addLine(x, y, x + 0.01, y + 0.01, pen=p)
示例4: undo
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def undo():
global b_epi_x, b_epi_y, b1, b2, b3, b4, epi_x, epi_y, p1, p2, p3, p4, btn_undo
epi_x = b_epi_x
epi_y = b_epi_y
p1 = b1
p2 = b2
p3 = b3
p4 = b4
rect[0] = QPointF(p1[0], p1[1])
rect[1] = QPointF(p2[0], p2[1])
rect[2] = QPointF(p3[0], p3[1])
rect[3] = QPointF(p4[0], p4[1])
scene.clear()
scene.addPolygon(rect, pen=p, brush=b)
l = len(epi_x)
for i in range(l):
scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p)
示例5: paint
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def paint(self, painter, option, parent):
if self.line.length() == 0.:
return
painter.setPen(self.arrow_pen)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver)
arrow_length = self.line.length() * .3 * (self.relative_length / 100.)
d = self.line.angle()
head_p1 = self.p2 - QtCore.QPointF(
num.sin(d*d2r + num.pi/3) * arrow_length,
num.cos(d*d2r + num.pi/3) * arrow_length)
head_p2 = self.p2 - QtCore.QPointF(
num.sin(d*d2r + num.pi - num.pi/3) * arrow_length,
num.cos(d*d2r + num.pi - num.pi/3) * arrow_length)
painter.drawLine(self.line)
painter.drawPolyline(*[head_p1, self.p2, head_p2])
示例6: position_to_grid_position
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def position_to_grid_position(self, position):
"""function position_to_grid_position
:param position: QPointF
returns int, int return (column,row) corresponding to the QPointF
"""
if not isinstance(position, QPointF):
raise ValueError('position must be a QPointF instance')
estimated_column = round(position.x() / (2 * self.get_size_tile()))
estimated_row = round(position.y() / (math.sqrt(3) * self.get_size_tile()))
for r in range(estimated_row - 3, estimated_row + 4):
for c in range(estimated_column - 3, estimated_column + 4):
field_index = self.grid_position_to_index(c, r)
if len(self.fields) > field_index and self.fields[field_index].enable and \
self.fields[field_index].hexa.containsPoint(position, Qt.OddEvenFill):
return c, r
return -1, -1
示例7: paint
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def paint(self, p, w, h):
if self._experiment.calibrator is not None:
mm_px = self._experiment.calibrator.mm_px
else:
mm_px = 1
self.clip(p, w, h)
# draw the black background
p.setBrush(QBrush(QColor(*self.background_color)))
p.drawRect(QRect(-1, -1, w + 2, h + 2))
imw, imh = self.get_unit_dims(w, h)
dx = self.x / mm_px
dy = self.y / mm_px
# rotate the coordinate transform around the position of the fish
tr = self.get_transform(w, h, dx, dy)
p.setTransform(tr)
for idx, idy in product(*self.get_tile_ranges(imw, imh, w, h, tr)):
self.draw_block(p, QPointF(idx * imw, idy * imh), w, h)
p.resetTransform()
示例8: keyPressEvent
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Delete or event.key() == QtCore.Qt.Key_Backspace:
self.delete()
elif event.key() == QtCore.Qt.Key_Escape:
self.setSelected(False)
elif event.key() == QtCore.Qt.Key_Return or event.key() == QtCore.Qt.Key_Enter:
self.mouseDoubleClickEvent()
elif event.key() == QtCore.Qt.Key_Up:
self.setPos(QtCore.QPointF(self.pos().x(), self.pos().y() - factor))
self.mouseMoveEvent()
elif event.key() == QtCore.Qt.Key_Down:
self.setPos(QtCore.QPointF(self.pos().x(), self.pos().y() + factor))
self.mouseMoveEvent()
elif event.key() == QtCore.Qt.Key_Left:
self.setPos(QtCore.QPointF(self.pos().x() - factor, self.pos().y()))
self.mouseMoveEvent()
elif event.key() == QtCore.Qt.Key_Right:
self.setPos(QtCore.QPointF(self.pos().x() + factor, self.pos().y()))
self.mouseMoveEvent()
示例9: setGridSize
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def setGridSize(self, size):
"""
Sets the grid size.
"""
action = self.session.action('toggle_grid')
size = clamp(size, 0)
if size <= 0 or not action.isChecked():
brush = QtGui.QBrush(QtCore.Qt.NoBrush)
else:
image = QtGui.QImage(size, size, QtGui.QImage.Format_RGB32)
image.fill(QtCore.Qt.white)
painter = QtGui.QPainter(image)
painter.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(80, 80, 80, 255)), 1, QtCore.Qt.SolidLine))
painter.drawPoint(QtCore.QPointF(0, 0))
painter.end()
brush = QtGui.QBrush(image)
self.setBackgroundBrush(brush)
示例10: startMove
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def startMove(self, delta, rate):
"""
Start the view movement.
:type delta: QtCore.QPointF
:type rate: float
"""
if self.mv_Timer:
self.stopMove()
# Move the view: this is needed before the timer so that if we keep
# moving the mouse fast outside the viewport rectangle we still are able
# to move the view; if we don't do this the timer may not have kicked in
# and thus we remain with a non-moving view with a unfocused graphics item.
self.moveBy(delta)
# Setup a timer for future move, so the view keeps moving
# also if we are not moving the mouse anymore but we are
# holding the position outside the viewport rect.
self.mv_Timer = QtCore.QTimer()
connect(self.mv_Timer.timeout, self.moveBy, delta)
self.mv_Timer.start(rate)
示例11: items
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def items(self, mixed=None, mode=QtCore.Qt.IntersectsItemShape, **kwargs):
"""
Returns a collection of items ordered from TOP to BOTTOM.
If no argument is supplied, an unordered list containing all the elements in the diagram is returned.
:type mixed: T <= QPointF | QRectF | QPolygonF | QPainterPath
:type mode: ItemSelectionMode
:rtype: list
"""
if mixed is None:
items = super().items()
elif isinstance(mixed, QtCore.QPointF):
x = mixed.x() - (Diagram.SelectionRadius / 2)
y = mixed.y() - (Diagram.SelectionRadius / 2)
w = Diagram.SelectionRadius
h = Diagram.SelectionRadius
items = super().items(QtCore.QRectF(x, y, w, h), mode)
else:
items = super().items(mixed, mode)
return sorted([
x for x in items
if (kwargs.get('nodes', True) and x.isNode() or
kwargs.get('edges', True) and x.isEdge() or
kwargs.get('labels', False) and x.isLabel()) and
x not in kwargs.get('skip', set())
], key=lambda i: i.zValue(), reverse=True)
示例12: visibleRect
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def visibleRect(self, margin=0):
"""
Returns a rectangle matching the area of visible items.
:type margin: float
:rtype: QtCore.QRectF
"""
items = self.items()
if items:
x = set()
y = set()
for item in items:
b = item.mapRectToScene(item.boundingRect())
x.update({b.left(), b.right()})
y.update({b.top(), b.bottom()})
return QtCore.QRectF(QtCore.QPointF(min(x) - margin, min(y) - margin), QtCore.QPointF(max(x) + margin, max(y) + margin))
return QtCore.QRectF()
示例13: importGenericNode
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def importGenericNode(d, i, e):
"""
Build a node using the given item type and QDomElement.
:type d: Diagram
:type i: Item
:type e: QDomElement
:rtype: AbstractNode
"""
geometry = e.firstChildElement('geometry')
node = d.factory.create(i, **{
'id': e.attribute('id'),
'height': int(geometry.attribute('height')),
'width': int(geometry.attribute('width'))
})
node.setPos(QtCore.QPointF(int(geometry.attribute('x')), int(geometry.attribute('y'))))
return node
#############################################
# ONTOLOGY DIAGRAMS : MAIN IMPORT
#################################
示例14: optimizeLabelPos
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def optimizeLabelPos(node):
"""
Perform updates on the position of the label of the given Domain o Range restriction node.
This is due to yEd not using the label to denote the 'exists' restriction and because Eddy
adds the label automatically, it may overlap some other elements hence we try to give it
some more visibility by moving it around the node till it overlaps less stuff.
:type node: T <= DomainRestrictionNode|RangeRestrictionNode
"""
if node.type() in {Item.DomainRestrictionNode, Item.RangeRestrictionNode}:
if node.restriction() is Restriction.Exists:
if not node.label.isMoved() and node.label.collidingItems():
x = [-30, -15, 0, 15, 30]
y = [0, 12, 22, 32, 44]
pos = node.label.pos()
for offset_x, offset_y in itertools.product(x, y):
node.label.setPos(pos + QtCore.QPointF(offset_x, offset_y))
if not node.label.collidingItems():
break
else:
node.label.setPos(pos)
#############################################
# MAIN IMPORT
#################################
示例15: __init__
# 需要導入模塊: from PyQt5 import QtCore [as 別名]
# 或者: from PyQt5.QtCore import QPointF [as 別名]
def __init__(self, width, height, color, border=None):
"""
Initialize the icon.
:type width: T <= int | float
:type height: T <= int | float
:type color: str
:type border: str
"""
pixmap = QtGui.QPixmap(width, height)
painter = QtGui.QPainter(pixmap)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
path = QtGui.QPainterPath()
path.addRect(QtCore.QRectF(QtCore.QPointF(0, 0), QtCore.QPointF(width, height)))
painter.fillPath(path, QtGui.QBrush(QtGui.QColor(color)))
if border:
painter.setPen(QtGui.QPen(QtGui.QColor(border), 0, QtCore.Qt.SolidLine))
painter.drawPath(path)
painter.end()
super().__init__(pixmap)