本文整理汇总了Python中qtpy.QtCore.QRectF方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QRectF方法的具体用法?Python QtCore.QRectF怎么用?Python QtCore.QRectF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtCore
的用法示例。
在下文中一共展示了QtCore.QRectF方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_ranges
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def draw_ranges(self) -> None:
"""Draw rectangle ranges."""
pen = QPen()
pen.setWidth(5)
for i, (tag, rect) in enumerate(self.ranges.items()):
range_color = QColor(color_num(i + 1))
range_color.setAlpha(30)
self.painter.setBrush(range_color)
range_color.setAlpha(255)
pen.setColor(range_color)
self.painter.setPen(pen)
cx = rect.x() * self.zoom
cy = rect.y() * -self.zoom
if rect.width():
self.painter.drawRect(QRectF(
QPointF(cx, cy),
QSizeF(rect.width(), rect.height()) * self.zoom
))
else:
self.draw_circle(QPointF(cx, cy), 3)
range_color.setAlpha(255)
pen.setColor(range_color)
self.painter.setPen(pen)
self.painter.drawText(QPointF(cx, cy) + QPointF(6, -6), tag)
self.painter.setBrush(Qt.NoBrush)
示例2: boundingRect
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def boundingRect(self):
srcPoint = self.mapFromScene(self.__srcPortCircle.centerInSceneCoords())
dstPoint = self.mapFromScene(self.__dstPortCircle.centerInSceneCoords())
penWidth = self.__defaultPen.width()
return QtCore.QRectF(
min(srcPoint.x(), dstPoint.x()),
min(srcPoint.y(), dstPoint.y()),
abs(dstPoint.x() - srcPoint.x()),
abs(dstPoint.y() - srcPoint.y()),
).adjusted(-penWidth/2, -penWidth/2, +penWidth/2, +penWidth/2)
示例3: generatePicture
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def generatePicture(self,data=None,redraw=False):
"""重新生成图形对象"""
# 重画或者只更新最后一个K线
if redraw:
self.pictures = []
elif self.pictures:
self.pictures.pop()
w = 0.4
bPen = self.bPen
bBrush = self.bBrush
rPen = self.rPen
rBrush = self.rBrush
self.low,self.high = (np.min(data['low']),np.max(data['high'])) if len(data)>0 else (0,1)
npic = len(self.pictures)
for (t, open0, close0, low0, high0) in data:
if t >= npic:
picture = QtGui.QPicture()
p = QtGui.QPainter(picture)
# 下跌蓝色(实心), 上涨红色(空心)
pen,brush,pmin,pmax = (bPen,bBrush,close0,open0)\
if open0 > close0 else (rPen,rBrush,open0,close0)
p.setPen(pen)
p.setBrush(brush)
# 画K线方块和上下影线
if open0 == close0:
p.drawLine(QtCore.QPointF(t-w,open0), QtCore.QPointF(t+w, close0))
else:
p.drawRect(QtCore.QRectF(t-w, open0, w*2, close0-open0))
if pmin > low0:
p.drawLine(QtCore.QPointF(t,low0), QtCore.QPointF(t, pmin))
if high0 > pmax:
p.drawLine(QtCore.QPointF(t,pmax), QtCore.QPointF(t, high0))
p.end()
self.pictures.append(picture)
# 手动重画
#----------------------------------------------------------------------
示例4: boundingRect
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def boundingRect(self):
return QtCore.QRectF(0,self.low,len(self.pictures),(self.high-self.low))
#----------------------------------------------------------------------
示例5: boundingRect
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def boundingRect(self):
return QtCore.QRectF(0,self.low,len(self.pictures),(self.high-self.low))
########################################################################
示例6: to_rect
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def to_rect(self, zoom: float) -> QRectF:
"""Return limit as QRectF type."""
return QRectF(
QPointF(self.x, -self.y) * zoom,
QPointF(self.sx, -self.sy) * zoom
)
示例7: __draw_link
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def __draw_link(self, vlink: VLink) -> None:
"""Draw a link."""
if vlink.name == VLink.FRAME or not vlink.points:
return
pen = QPen()
# Rearrange: Put the nearest point to the next position.
qpoints = convex_hull(
[(c.x * self.zoom, c.y * -self.zoom)
for c in vlink.points_pos(self.vpoints)], as_qpoint=True)
if (
self.select_mode == SelectMode.LINK
and self.vlinks.index(vlink) in self.selections
):
pen.setWidth(self.link_width + 6)
pen.setColor(Qt.black if self.monochrome else QColor(161, 16, 239))
self.painter.setPen(pen)
self.painter.drawPolygon(*qpoints)
pen.setWidth(self.link_width)
pen.setColor(Qt.black if self.monochrome else QColor(*vlink.color))
self.painter.setPen(pen)
self.painter.drawPolygon(*qpoints)
if not self.show_point_mark:
return
pen.setColor(Qt.darkGray)
self.painter.setPen(pen)
p_count = len(qpoints)
cen_x = sum(p.x() for p in qpoints) / p_count
cen_y = sum(p.y() for p in qpoints) / p_count
self.painter.drawText(
QRectF(cen_x - 50, cen_y - 50, 100, 100),
Qt.AlignCenter,
f'[{vlink.name}]'
)
示例8: adjust_drawing
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def adjust_drawing(self):
"""
When the user resizes the window, the drawing elements follow the x-positions of the corresponding
attribute_widgets.
"""
for item in self.graphic_items:
item.move_to_right_position()
for conn in self.connections:
conn.adjust()
iq = self.module_widgets[0]
for index, prop in enumerate(["input", "acbandwidth", "frequency",
"bandwidth", "quadrature_factor", "gain",
"amplitude", "output_direct"][::2]):
widget = iq.attribute_widgets[prop]
self.frames[index].setFixedSize(widget.width() + iq.main_layout.spacing(), self.height())
self.frames[index].move(widget.x() + iq.pos().x() - iq.main_layout.spacing() / 2, 0)
self.frames_drawing[index].setFixedSize(widget.width() + iq.main_layout.spacing(), self.height())
self.frames_drawing[index].move(widget.x() + iq.pos().x() - self.view.pos().x() - iq.main_layout.spacing() / 2,
0)
self.scene.setSceneRect(QtCore.QRectF(self.view.rect()))
#x, y = self.view.pos().x(), self.view.pos().y()
button_width = 150
self.button_hide.move(self.width()/2 - button_width/2, self.height() - 17)
self.button_hide.setFixedWidth(button_width)
self.button_hide.raise_()
示例9: generatePicture
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def generatePicture(self,data=None,redraw=False):
"""重新生成图形对象"""
# 重画或者只更新最后一个K线
if redraw:
self.pictures = []
elif self.pictures:
self.pictures.pop()
w = 0.4
bPen = self.bPen
bBrush = self.bBrush
rPen = self.rPen
rBrush = self.rBrush
low,high = (data[0]['low'],data[0]['high']) if len(data)>0 else (0,1)
for (t, open0, close0, low0, high0) in data:
# t 并不是时间,是序列
if t >= len(self.pictures):
# 每一个K线创建一个picture
picture = QtGui.QPicture()
p = QtGui.QPainter(picture)
low, high = (min(low, low0), max(high, high0))
# 下跌蓝色(实心), 上涨红色(空心)
pen, brush, pmin, pmax = (bPen, bBrush, close0, open0)\
if open0 > close0 else (rPen, rBrush, open0, close0)
p.setPen(pen)
p.setBrush(brush)
# 画K线方块和上下影线
if open0 == close0:
p.drawLine(QtCore.QPointF(t-w,open0), QtCore.QPointF(t+w, close0))
else:
p.drawRect(QtCore.QRectF(t-w, open0, w*2, close0-open0))
if pmin > low0:
p.drawLine(QtCore.QPointF(t,low0), QtCore.QPointF(t, pmin))
if high0 > pmax:
p.drawLine(QtCore.QPointF(t,pmax), QtCore.QPointF(t, high0))
p.end()
# 添加到队列中
self.pictures.append(picture)
# 更新所有K线的最高/最低
self.low,self.high = low,high
# 手动重画
#----------------------------------------------------------------------
示例10: __init__
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def __init__(
self,
mechanism: Dict[str, Any],
path: Sequence[Sequence[_Coord]],
vpoints: List[VPoint] = None,
vlinks: List[VLink] = None,
parent: QWidget = None
):
"""Input link and path data."""
super(_DynamicCanvas, self).__init__(parent)
self.mechanism = mechanism
self.vpoints = vpoints or []
self.vlinks = vlinks or []
self.no_mechanism = not self.vpoints or not self.vlinks
use_norm = self.no_mechanism and (
self.mechanism.get('shape_only', False)
or self.mechanism.get('wavelet_mode', False))
# Target path
same: Dict[int, int] = self.mechanism['same']
target_path: _TargetPath = self.mechanism['target']
for i, p in target_path.items():
for j in range(i):
if j in same:
i -= 1
self.target_path[i] = norm_path(p) if use_norm else p
self.path.path = []
for i, p in enumerate(path):
if i in self.target_path and use_norm:
self.path.path.append(norm_path(efd_fitting(p)))
else:
self.path.path.append(p)
self.__index = 0
self.__interval = 1
self.__path_count = max(len(path) for path in self.path.path) - 1
self.pos = []
# Error
self.error = False
self.__no_error = 0
if self.no_mechanism:
return
# Ranges
ranges: Dict[int, _Range] = self.mechanism['placement']
self.ranges.update({f"P{i}": QRectF(
QPointF(values[0] - values[2], values[1] + values[2]),
QSizeF(values[2] * 2, values[2] * 2)
) for i, values in ranges.items()})
# Timer
self.__timer = QTimer()
self.__timer.timeout.connect(self.__change_index)
self.__timer.start(18)
示例11: paintEvent
# 需要导入模块: from qtpy import QtCore [as 别名]
# 或者: from qtpy.QtCore import QRectF [as 别名]
def paintEvent(self, event: QPaintEvent) -> None:
"""Using a QPainter under 'self',
so just change QPen or QBrush before painting.
"""
if not self.__grab_mode:
self.painter.begin(self)
self.painter.fillRect(event.rect(), QBrush(Qt.white))
# Translation
self.painter.translate(self.ox, self.oy)
# Background
if not self.background.isNull():
rect = self.background.rect()
self.painter.setOpacity(self.background_opacity)
self.painter.drawImage(QRectF(
self.background_offset * self.zoom,
QSizeF(rect.width(), rect.height())
* self.background_scale * self.zoom
), self.background, QRectF(rect))
self.painter.setOpacity(1)
# Show frame
pen = QPen(Qt.blue)
pen.setWidth(1)
self.painter.setPen(pen)
self.painter.setFont(QFont("Arial", self.font_size))
# Draw origin lines
if self.show_ticks not in {_TickMark.SHOW, _TickMark.SHOW_NUM}:
return
pen.setColor(Qt.gray)
self.painter.setPen(pen)
x_l = -self.ox
x_r = self.width() - self.ox
self.painter.drawLine(QPointF(x_l, 0), QPointF(x_r, 0))
y_t = self.height() - self.oy
y_b = -self.oy
self.painter.drawLine(QPointF(0, y_b), QPointF(0, y_t))
def indexing(v: float) -> int:
"""Draw tick."""
return int(v / self.zoom - v / self.zoom % 5)
# Draw tick
for x in range(indexing(x_l), indexing(x_r) + 1, 5):
if x == 0:
continue
is_ten = x % 10 == 0
end = QPointF(x * self.zoom, -10 if is_ten else -5)
self.painter.drawLine(QPointF(x, 0) * self.zoom, end)
if self.show_ticks == _TickMark.SHOW_NUM and is_ten:
self.painter.drawText(end + QPointF(0, 3), f"{x}")
for y in range(indexing(y_b), indexing(y_t) + 1, 5):
if y == 0:
continue
is_ten = y % 10 == 0
end = QPointF(10 if is_ten else 5, y * self.zoom)
self.painter.drawLine(QPointF(0, y) * self.zoom, end)
if self.show_ticks == _TickMark.SHOW_NUM and is_ten:
self.painter.drawText(end + QPointF(3, 0), f"{-y}")
# Please to call the "end" method when ending paint event.