本文整理汇总了Python中AnyQt.QtCore.QRectF.center方法的典型用法代码示例。如果您正苦于以下问题:Python QRectF.center方法的具体用法?Python QRectF.center怎么用?Python QRectF.center使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QRectF
的用法示例。
在下文中一共展示了QRectF.center方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: grab_svg
# 需要导入模块: from AnyQt.QtCore import QRectF [as 别名]
# 或者: from AnyQt.QtCore.QRectF import center [as 别名]
def grab_svg(scene):
"""
Return a SVG rendering of the scene contents.
Parameters
----------
scene : :class:`CanvasScene`
"""
from AnyQt.QtSvg import QSvgGenerator
svg_buffer = QBuffer()
gen = QSvgGenerator()
gen.setOutputDevice(svg_buffer)
items_rect = scene.itemsBoundingRect().adjusted(-10, -10, 10, 10)
if items_rect.isNull():
items_rect = QRectF(0, 0, 10, 10)
width, height = items_rect.width(), items_rect.height()
rect_ratio = float(width) / height
# Keep a fixed aspect ratio.
aspect_ratio = 1.618
if rect_ratio > aspect_ratio:
height = int(height * rect_ratio / aspect_ratio)
else:
width = int(width * aspect_ratio / rect_ratio)
target_rect = QRectF(0, 0, width, height)
source_rect = QRectF(0, 0, width, height)
source_rect.moveCenter(items_rect.center())
gen.setSize(target_rect.size().toSize())
gen.setViewBox(target_rect)
painter = QPainter(gen)
# Draw background.
painter.setBrush(QBrush(Qt.white))
painter.drawRect(target_rect)
# Render the scene
scene.render(painter, target_rect, source_rect)
painter.end()
buffer_str = bytes(svg_buffer.buffer())
return buffer_str.decode("utf-8")