本文整理匯總了Python中PySide2.QtCore.QPointF方法的典型用法代碼示例。如果您正苦於以下問題:Python QtCore.QPointF方法的具體用法?Python QtCore.QPointF怎麽用?Python QtCore.QPointF使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PySide2.QtCore
的用法示例。
在下文中一共展示了QtCore.QPointF方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: paintEvent
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def paintEvent(self, event):
super(CircularBrush, self).paintEvent(event)
# draw brush
if hasattr(self, 'brush_state') and self.brush_state.draw:
painter = QPainter()
shapes = self.create_brush_shape()
for shape in shapes:
shape = [QPointF(point[0], point[1]) for point in shape]
path = QPainterPath()
start_pos = shape.pop(0)
path.moveTo(start_pos)
[path.lineTo(point) for point in shape]
painter.setRenderHint(painter.Antialiasing)
# painter.setRenderHint(painter.HighQualityAnti)
painter.begin(self)
painter.setPen(QPen(Qt.red, 1))
painter.drawPath(path)
painter.end()
示例2: updateIndicatorPos
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def updateIndicatorPos(self, eventPos):
"""
move indicator cursor to correct position under mouse
"""
rect = self.getImageDims()
gridSize = rect.width() / self.gridSize.width()
latentSize = self.latentSize * gridSize
centerOffset = latentSize // 2
scenePos = QGraphicsView.mapToScene(self, eventPos)
scenePos -= QPointF(centerOffset, centerOffset) #center latentIndicator around mouse
roundPos = QPoint(int(gridSize * round(scenePos.x()/gridSize)), int(gridSize * round(scenePos.y()/gridSize)))
roundPos.setX(int(max(-centerOffset, min(roundPos.x(), rect.width() - ( latentSize - centerOffset )))))
roundPos.setY(int(max(-centerOffset, min(roundPos.y(), rect.height() - ( latentSize - centerOffset )))))
self._latentIndicator.setPos(roundPos)
示例3: makeContourPolygon
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def makeContourPolygon(self, coordinates):
"""Add airfoil points as GraphicsItem to the scene"""
# instantiate a graphics item
contour = gic.GraphicsCollection()
# make it polygon type and populate its points
points = [QtCore.QPointF(x, y) for x, y in zip(*coordinates)]
contour.Polygon(QtGui.QPolygonF(points), self.name)
# set its properties
contour.pen.setColor(self.pencolor)
contour.pen.setWidthF(self.penwidth)
# no pen thickness change when zoomed
contour.pen.setCosmetic(True)
contour.brush.setColor(self.brushcolor)
self.contourPolygon = GraphicsItem.GraphicsItem(contour)
示例4: __init__
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def __init__(self, edge, arrow_location="end", arrow_direction='down', parent=None):
super().__init__(parent)
self.edge = edge
self.rect = None
self._start = QPointF(*self.edge.coordinates[0])
self.coords = [self.create_point(c) for c in self.edge.coordinates]
self.end = self.coords[-1]
self.start = self.coords[0]
self.color = EDGE_COLORS.get(self.edge.sort, EDGE_COLORS[EdgeSort.DIRECT_JUMP])
self.arrow = self._make_arrow(arrow_location, arrow_direction)
self.style = EDGE_STYLES.get(self.edge.sort, EDGE_STYLES[EdgeSort.DIRECT_JUMP])
self.path = self._make_path()
self._hovered = False
self.setAcceptHoverEvents(True)
示例5: _make_arrow
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def _make_arrow(self, location, direction):
if location == "start":
coord = self.start
else:
coord = self.end
if direction == "down":
return [QPointF(coord.x() - 3, coord.y()), QPointF(coord.x() + 3, coord.y()),
QPointF(coord.x(), coord.y() + 6)]
elif direction == "right":
return [QPointF(coord.x(), coord.y() - 3), QPointF(coord.x(), coord.y() + 3),
QPointF(coord.x() + 6, coord.y())]
elif direction == "left":
return [QPointF(coord.x(), coord.y() - 3), QPointF(coord.x(), coord.y() + 3),
QPointF(coord.x() - 6, coord.y())]
else:
raise NotImplementedError("Direction %s is not supported yet." % direction)
示例6: move
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def move(self, rects, cursor):
x = cursor.x() - self.reference_x
y = cursor.y() - self.reference_y
if self.snap is not None:
x, y = snap(x, y, self.snap)
width = self.rect.width()
height = self.rect.height()
self.rect.setTopLeft(QtCore.QPointF(x, y))
self.rect.setWidth(width)
self.rect.setHeight(height)
self.apply_relative_transformation(rects)
示例7: updateIndicatorSize
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def updateIndicatorSize(self, stroke=3, offset=2, crossSize=10):
"""
draw a box and crosshair under mouse cursor as rectangle of size latentSize
"""
multiplier = 1 #TODO optional: scale indicator with zoom level
stroke *= multiplier
offset *= multiplier
crossSize *= multiplier
halfStroke = stroke / 2
rect = self.getImageDims()
latentSize = self.latentSize * rect.width() / self.gridSize.width()
halfSize = latentSize / 2
crossSize = min(crossSize, int(halfSize - 3))
pixmap = QPixmap(QSize(int(latentSize + stroke + offset), int(latentSize + stroke + offset)))
#fill rectangle with transparent color
pixmap.fill(QColor(0,0,0,0)) #transparent
painter = QPainter(pixmap)
r = QRectF(QPoint(), QSizeF(latentSize, latentSize))
r.adjust(offset+halfStroke, offset+halfStroke, -halfStroke, -halfStroke)
#draw shadow under rectangle
pen = QPen(QColor(50, 50, 50, 100), stroke) #shadow
painter.setPen(pen)
painter.drawRect(r)
if crossSize > 4:
painter.drawLine(QPointF(offset+halfSize, offset+halfSize-crossSize), QPointF(offset+halfSize, offset+halfSize+crossSize))
painter.drawLine(QPointF(offset+halfSize-crossSize, offset+halfSize), QPointF(offset+halfSize+crossSize, offset+halfSize))
r.adjust(-offset, -offset, -offset, -offset)
pen = QPen(QColor(styleColor[0], styleColor[1], styleColor[2], 200), stroke)
painter.setPen(pen)
painter.drawRect(r)
if crossSize > 4:
painter.drawLine(QPointF(halfSize, halfSize - crossSize), QPointF(halfSize, halfSize + crossSize))
painter.drawLine(QPointF(halfSize - crossSize, halfSize), QPointF(halfSize + crossSize, halfSize))
painter.end()
self._latentIndicator.setPixmap(pixmap)
示例8: roundToGlobalGridCoords
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def roundToGlobalGridCoords(self, pos):
"""
return a global coordinate for a latent grid position
"""
roundedGridPos = self.getGridCoords(pos)
imageRect = self.getImageDims()
pixelPos = QPointF(roundedGridPos.x() * imageRect.width() / self.gridSize.width(), roundedGridPos.y() * imageRect.height() / self.gridSize.height())
return QGraphicsView.mapToGlobal(self, QGraphicsView.mapFromScene(self, pixelPos))
示例9: Line
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def Line(self, x1, y1, x2, y2):
eps = 0.01
p1 = QtCore.QPointF(x1-eps, y1-eps)
p2 = QtCore.QPointF(x2+eps, y2+eps)
self.rect = QtCore.QRectF(p1, p2)
self.shape.addRect(self.rect)
self.method = 'drawLine'
self.args = [x1, y1, x2, y2]
示例10: fitAirfoilInView
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def fitAirfoilInView(self):
if len(self.parent.airfoils) == 0:
return
# get bounding rect in scene coordinates
item = self.parent.airfoil.contourPolygon
rectf = item.boundingRect()
rf = copy.deepcopy(rectf)
center = rf.center()
# make 4% smaller than width of graphicsview
w = 1.04 * rf.width()
h = 1.04 * rf.height()
# do not use setWidhtF and setHeightF here!!!
rf.setWidth(w)
rf.setHeight(h)
# shift center of rectf
cx = center.x()
cy = center.y()
rf.moveCenter(QtCore.QPointF(cx, cy))
self.parent.view.fitInView(rf,
aspectRadioMode=QtCore.Qt.KeepAspectRatio)
# it is IMPORTANT that this is called after fitInView
# adjust airfoil marker size to MARKERSIZE setting
self.parent.view.adjustMarkerSize()
# cache view to be able to keep it during resize
self.parent.view.getSceneFromView()
示例11: create_point
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def create_point(self, stuff):
return QPointF(*stuff) - self._start
示例12: _get_distance
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def _get_distance(pt0: QPointF, pt1: QPointF) -> float:
d = (pt1.x() - pt0.x()) ** 2 + (pt1.y() - pt0.y()) ** 2
return math.sqrt(d)
示例13: _get_line_end
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def _get_line_end(self, i: int) -> QPointF:
pt0 = self.coords[i]
pt1 = self.coords[i + 1] if i + 1 < len(self.coords) else self.coords[0]
rat = self._radius / self._get_distance(pt0, pt1)
if rat > 0.5:
rat = 0.5
return QPointF(rat * pt0.x() + (1.0 - rat) * pt1.x(), rat * pt0.y() + (1.0 - rat) * pt1.y())
示例14: _paint_insn_indicators
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def _paint_insn_indicators(self, **kwargs):
scene = self.view.scene() # type: QGraphicsScene
for item in self._insn_indicators:
scene.removeItem(item)
self._insn_indicators.clear()
for selected_insn_addr in self.disasm_view.infodock.selected_insns:
pos = self._get_pos_from_addr(selected_insn_addr)
if pos is None:
continue
pos -= 1 # this is the top-left x coordinate of our arrow body (the rectangle)
pen = QPen(Qt.yellow)
brush = QBrush(Qt.yellow)
rect = QRectF(pos, 0, 2, 5)
# rectangle
item = scene.addRect(rect, pen, brush)
self._insn_indicators.append(item)
# triangle
triangle = QPolygonF()
triangle.append(QPointF(pos - 1, 5))
triangle.append(QPointF(pos + 3, 5))
triangle.append(QPointF(pos + 1, 7))
triangle.append(QPointF(pos - 1, 5))
item = scene.addPolygon(triangle, pen, brush)
self._insn_indicators.append(item)
示例15: request_relayout
# 需要導入模塊: from PySide2 import QtCore [as 別名]
# 或者: from PySide2.QtCore import QPointF [as 別名]
def request_relayout(self):
node_coords, edges = self._layout_graph()
self._edges = edges
categorize_edges(self.disasm, edges)
if not node_coords:
print("Failed to get node_coords")
return
# layout nodes
for block in self.blocks:
x, y = node_coords[block.addr]
block.setPos(x, y)
scene = self.scene()
# remove exiting arrows
for arrow in self._arrows:
scene.removeItem(arrow)
self._arrows.clear()
for edge in self._edges:
arrow = QDisasmGraphArrow(edge, self.disasm_view, self.infodock)
self._arrows.append(arrow)
scene.addItem(arrow)
arrow.setPos(QPointF(*edge.coordinates[0]))