本文整理汇总了Python中AnyQt.QtCore.QRectF.moveCenter方法的典型用法代码示例。如果您正苦于以下问题:Python QRectF.moveCenter方法的具体用法?Python QRectF.moveCenter怎么用?Python QRectF.moveCenter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QRectF
的用法示例。
在下文中一共展示了QRectF.moveCenter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from AnyQt.QtCore import QRectF [as 别名]
# 或者: from AnyQt.QtCore.QRectF import moveCenter [as 别名]
def paintEvent(self, event):
if self.__pixmap.isNull():
return
sourcerect = QRect(QPoint(0, 0), self.__pixmap.size())
pixsize = QSizeF(self.__pixmap.size())
rect = self.contentsRect()
pixsize.scale(QSizeF(rect.size()), Qt.KeepAspectRatio)
targetrect = QRectF(QPointF(0, 0), pixsize)
targetrect.moveCenter(QPointF(rect.center()))
painter = QPainter(self)
painter.setRenderHint(QPainter.SmoothPixmapTransform)
painter.drawPixmap(targetrect, self.__pixmap, QRectF(sourcerect))
painter.end()
示例2: grab_svg
# 需要导入模块: from AnyQt.QtCore import QRectF [as 别名]
# 或者: from AnyQt.QtCore.QRectF import moveCenter [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")
示例3: paint
# 需要导入模块: from AnyQt.QtCore import QRectF [as 别名]
# 或者: from AnyQt.QtCore.QRectF import moveCenter [as 别名]
def paint(self, painter, option, widget=0):
if self._pixmap.isNull():
return
rect = self.contentsRect()
pixsize = QSizeF(self._pixmap.size())
aspectmode = (Qt.KeepAspectRatio if self._keepAspect
else Qt.IgnoreAspectRatio)
pixsize.scale(rect.size(), aspectmode)
pixrect = QRectF(QPointF(0, 0), pixsize)
pixrect.moveCenter(rect.center())
painter.save()
painter.setPen(QPen(QColor(0, 0, 0, 50), 3))
painter.drawRoundedRect(pixrect, 2, 2)
painter.setRenderHint(QPainter.SmoothPixmapTransform)
source = QRectF(QPointF(0, 0), QSizeF(self._pixmap.size()))
painter.drawPixmap(pixrect, self._pixmap, source)
painter.restore()
示例4: paint
# 需要导入模块: from AnyQt.QtCore import QRectF [as 别名]
# 或者: from AnyQt.QtCore.QRectF import moveCenter [as 别名]
def paint(self, painter, option, widget=0):
if self._pixmap.isNull():
return
rect = self.contentsRect()
pixsize = QSizeF(self._pixmap.size())
aspectmode = (Qt.KeepAspectRatio if self._keepAspect else Qt.IgnoreAspectRatio)
if self._crop:
height, width = pixsize.height(), pixsize.width()
diff = abs(height - width)
if height > width:
y, x = diff / 2, 0
h, w = height - diff, width
else:
x, y = diff / 2, 0
w, h = width - diff, height
source = QRectF(x, y, w, h)
pixrect = QRectF(QPointF(0, 0), rect.size())
else:
source = QRectF(QPointF(0, 0), pixsize)
pixsize.scale(rect.size(), aspectmode)
pixrect = QRectF(QPointF(0, 0), pixsize)
if self._subset:
painter.setOpacity(1.0)
else:
painter.setOpacity(0.35)
pixrect.moveCenter(rect.center())
painter.save()
painter.setPen(QPen(QColor(0, 0, 0, 50), 3))
painter.drawRoundedRect(pixrect, 2, 2)
painter.setRenderHint(QPainter.SmoothPixmapTransform)
painter.drawPixmap(pixrect, self._pixmap, source)
painter.restore()