本文整理汇总了Python中PyQt5.QtCore.QSize.scale方法的典型用法代码示例。如果您正苦于以下问题:Python QSize.scale方法的具体用法?Python QSize.scale怎么用?Python QSize.scale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QSize
的用法示例。
在下文中一共展示了QSize.scale方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paintEvent
# 需要导入模块: from PyQt5.QtCore import QSize [as 别名]
# 或者: from PyQt5.QtCore.QSize import scale [as 别名]
def paintEvent(self, event, *args):
""" Custom paint event """
self.mutex.lock()
# Paint custom frame image on QWidget
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing, True)
# Fill background black
painter.fillRect(event.rect(), self.palette().window())
if self.current_image:
# DRAW FRAME
# Calculate new frame image size, maintaining aspect ratio
pixSize = self.current_image.size()
pixSize.scale(event.rect().size(), Qt.KeepAspectRatio)
# Scale image
scaledPix = self.current_image.scaled(pixSize, Qt.KeepAspectRatio, Qt.SmoothTransformation)
# Calculate center of QWidget and Draw image
center = self.centeredViewport(self.width(), self.height())
painter.drawImage(center, scaledPix)
if self.transforming_clip:
# Draw transform handles on top of video preview
# Get framerate
fps = get_app().project.get(["fps"])
fps_float = float(fps["num"]) / float(fps["den"])
# Determine frame # of clip
start_of_clip = round(float(self.transforming_clip.data["start"]) * fps_float)
position_of_clip = (float(self.transforming_clip.data["position"]) * fps_float) + 1
playhead_position = float(get_app().window.preview_thread.current_frame)
clip_frame_number = round(playhead_position - position_of_clip) + start_of_clip + 1
# Get properties of clip at current frame
raw_properties = json.loads(self.transforming_clip_object.PropertiesJSON(clip_frame_number))
# Get size of current video player
player_width = self.rect().width()
player_height = self.rect().height()
# Determine original size of clip's reader
source_width = self.transforming_clip.data['reader']['width']
source_height = self.transforming_clip.data['reader']['height']
source_size = QSize(source_width, source_height)
# Determine scale of clip
scale = self.transforming_clip.data['scale']
if scale == openshot.SCALE_FIT:
source_size.scale(player_width, player_height, Qt.KeepAspectRatio)
elif scale == openshot.SCALE_STRETCH:
source_size.scale(player_width, player_height, Qt.IgnoreAspectRatio)
elif scale == openshot.SCALE_CROP:
width_size = QSize(player_width, round(player_width / (float(source_width) / float(source_height))))
height_size = QSize(round(player_height / (float(source_height) / float(source_width))), player_height)
if width_size.width() >= player_width and width_size.height() >= player_height:
source_size.scale(width_size.width(), width_size.height(), Qt.KeepAspectRatio)
else:
source_size.scale(height_size.width(), height_size.height(), Qt.KeepAspectRatio)
# Get new source width / height (after scaling mode applied)
source_width = source_size.width()
source_height = source_size.height()
# Init X/Y
x = 0.0
y = 0.0
# Get scaled source image size (scale_x, scale_y)
sx = max(float(raw_properties.get('scale_x').get('value')), 0.001)
sy = max(float(raw_properties.get('scale_y').get('value')), 0.001)
scaled_source_width = source_width * sx
scaled_source_height = source_height * sy
# Determine gravity of clip
gravity = self.transforming_clip.data['gravity']
if gravity == openshot.GRAVITY_TOP_LEFT:
x += self.centeredViewport(self.width(), self.height()).x() # nudge right
y += self.centeredViewport(self.width(), self.height()).y() # nudge down
elif gravity == openshot.GRAVITY_TOP:
x = (player_width - scaled_source_width) / 2.0 # center
y += self.centeredViewport(self.width(), self.height()).y() # nudge down
elif gravity == openshot.GRAVITY_TOP_RIGHT:
x = player_width - scaled_source_width # right
x -= self.centeredViewport(self.width(), self.height()).x() # nudge left
y += self.centeredViewport(self.width(), self.height()).y() # nudge down
elif gravity == openshot.GRAVITY_LEFT:
y = (player_height - scaled_source_height) / 2.0 # center
x += self.centeredViewport(self.width(), self.height()).x() # nudge right
elif gravity == openshot.GRAVITY_CENTER:
x = (player_width - scaled_source_width) / 2.0 # center
y = (player_height - scaled_source_height) / 2.0 # center
elif gravity == openshot.GRAVITY_RIGHT:
x = player_width - scaled_source_width # right
y = (player_height - scaled_source_height) / 2.0 # center
x -= self.centeredViewport(self.width(), self.height()).x() # nudge left
#.........这里部分代码省略.........