本文整理汇总了Python中PyQt5.QtCore.Qt.IgnoreAspectRatio方法的典型用法代码示例。如果您正苦于以下问题:Python Qt.IgnoreAspectRatio方法的具体用法?Python Qt.IgnoreAspectRatio怎么用?Python Qt.IgnoreAspectRatio使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.Qt
的用法示例。
在下文中一共展示了Qt.IgnoreAspectRatio方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fit_in_view
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import IgnoreAspectRatio [as 别名]
def _fit_in_view(view, rect, flags=Qt.IgnoreAspectRatio):
if view.scene() is None or rect.isNull():
return
view.last_scene_roi = rect
unity = view.transform().mapRect(QRectF(0, 0, 1, 1))
view.scale(1 / unity.width(), 1 / unity.height())
view_rect = view.viewport().rect()
scene_rect = view.transform().mapRect(rect)
xratio = view_rect.width() / scene_rect.width()
yratio = view_rect.height() / scene_rect.height()
if flags == Qt.KeepAspectRatio:
xratio = yratio = min(xratio, yratio)
elif flags == Qt.KeepAspectRatioByExpanding:
xratio = yratio = max(xratio, yratio)
view.scale(xratio, yratio)
view.centerOn(rect.center())
# name must match because we're overriding QMainWindow method
示例2: updateImage
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import IgnoreAspectRatio [as 别名]
def updateImage(self, opencv_rgb_image):
self.cv_img_rgb = opencv_rgb_image
height, width, channel = self.cv_img_rgb.shape
bytesPerLine = 3 * width
self.q_image = QImage(self.cv_img_rgb.data, width,
height, bytesPerLine, QImage.Format_RGB888)
# self.QPixmap=QPixmap.fromImage(self.q_image)
# scaredPixmap = self.QPixmap.scaled(self,self.frame_lbl.frameSize, aspectRatioMode=Qt.IgnoreAspectRatio)
self.frame_lbl.setPixmap(QPixmap.fromImage(self.q_image).scaled(self.frame_lbl.size(), aspectRatioMode=Qt.KeepAspectRatio))
示例3: __init__
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import IgnoreAspectRatio [as 别名]
def __init__(self):
QGraphicsView.__init__(self)
# Image is displayed as a QPixmap in a QGraphicsScene attached to this QGraphicsView.
self.scene = QGraphicsScene()
self.setScene(self.scene)
# Store a local handle to the scene's current image pixmap.
self._pixmapHandle = None
# Image aspect ratio mode.
# !!! ONLY applies to full image. Aspect ratio is always ignored when zooming.
# Qt.IgnoreAspectRatio: Scale image to fit viewport.
# Qt.KeepAspectRatio: Scale image to fit inside viewport, preserving aspect ratio.
# Qt.KeepAspectRatioByExpanding: Scale image to fill the viewport, preserving aspect ratio.
self.aspectRatioMode = Qt.KeepAspectRatio
# Scroll bar behaviour.
# Qt.ScrollBarAlwaysOff: Never shows a scroll bar.
# Qt.ScrollBarAlwaysOn: Always shows a scroll bar.
# Qt.ScrollBarAsNeeded: Shows a scroll bar only when zoomed.
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
# Stack of QRectF zoom boxes in scene coordinates.
self.zoomStack = []
# Flags for enabling/disabling mouse interaction.
self.canZoom = True
self.canPan = True
示例4: updateViewer
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import IgnoreAspectRatio [as 别名]
def updateViewer(self):
""" Show current zoom (if showing entire image, apply current aspect ratio mode).
"""
if not self.hasImage():
return
if len(self.zoomStack) and self.sceneRect().contains(self.zoomStack[-1]):
self.fitInView(self.zoomStack[-1], Qt.IgnoreAspectRatio) # Show zoomed rect (ignore aspect ratio).
else:
self.zoomStack = [] # Clear the zoom stack (in case we got here because of an invalid zoom).
self.fitInView(self.sceneRect(), self.aspectRatioMode) # Show entire image (use current aspect ratio mode).
示例5: makeItem
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import IgnoreAspectRatio [as 别名]
def makeItem(self, size, cname):
item = QListWidgetItem(self)
item.setData(Qt.UserRole + 1, cname) # 把颜色放进自定义的data里面
item.setSizeHint(size)
label = QLabel(self) # 自定义控件
label.setMargin(2) # 往内缩进2
label.resize(size)
pixmap = QPixmap(size.scaled(96, 96, Qt.IgnoreAspectRatio)) # 调整尺寸
pixmap.fill(QColor(cname))
label.setPixmap(pixmap)
self.setItemWidget(item, label)
示例6: _do_load_thumbnail
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import IgnoreAspectRatio [as 别名]
def _do_load_thumbnail(self):
pixmap = QPixmap(self.path)
if not pixmap.isNull():
self.icon.setPixmap(
pixmap.scaled(
48, 48, Qt.IgnoreAspectRatio, Qt.SmoothTransformation
)
)
示例7: apply_pixmap
# 需要导入模块: from PyQt5.QtCore import Qt [as 别名]
# 或者: from PyQt5.QtCore.Qt import IgnoreAspectRatio [as 别名]
def apply_pixmap(self):
"""Apply a scaled pixmap without modifying the dimension of the original one."""
if self.pixmap:
self.setPixmap(
self.pixmap.scaled(
self.size(), Qt.IgnoreAspectRatio, Qt.SmoothTransformation
)
)