本文整理汇总了Python中PyQt5.QtCore.QPropertyAnimation.setDuration方法的典型用法代码示例。如果您正苦于以下问题:Python QPropertyAnimation.setDuration方法的具体用法?Python QPropertyAnimation.setDuration怎么用?Python QPropertyAnimation.setDuration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QPropertyAnimation
的用法示例。
在下文中一共展示了QPropertyAnimation.setDuration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Tab
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
class Tab(QObject):
def __init__(self, parent):
QObject.__init__(self, parent)
self._toolbar = parent
self.icon = None
self.text = ""
self.has_menu = False
self.enabled = True
self._fader = 0
self._animator = QPropertyAnimation(self)
self._animator.setPropertyName(b"fader")
self._animator.setTargetObject(self)
def fade_in(self):
self._animator.stop()
self._animator.setDuration(80)
self._animator.setEndValue(1)
self._animator.start()
def fade_out(self):
self._animator.stop()
self._animator.setDuration(160)
self._animator.setEndValue(0)
self._animator.start()
def _set_fader(self, value):
self._fader = value
self._toolbar.update()
def _get_fader(self):
return self._fader
fader = pyqtProperty(float, fget=_get_fader, fset=_set_fader)
示例2: MoveSymbol
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
class MoveSymbol(QUndoCommand):
''' Undo/Redo command for moving symbols '''
def __init__(self, symbol_id, old_pos, new_pos, animate=False):
super(MoveSymbol, self).__init__()
self.setText('Move symbol')
self.symbol = symbol_id
self.old_pos = old_pos
self.new_pos = new_pos
if animate:
self.animation = QPropertyAnimation(self.symbol, "position")
self.animation.setDuration(500)
self.animation.setStartValue(self.old_pos)
self.animation.setEndValue(self.new_pos)
self.animation.setEasingCurve(QEasingCurve.OutCirc)
def undo(self):
''' Undo a symbol move '''
self.symbol.position = self.old_pos
try:
self.symbol.decisionParent.updateConnectionPointPosition()
except AttributeError:
pass
def redo(self):
''' Apply a symbol move '''
try:
self.animation.start()
except AttributeError:
self.symbol.position = self.new_pos
try:
self.symbol.decisionParent.updateConnectionPointPosition()
except AttributeError:
pass
示例3: createPositionAnimation
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
def createPositionAnimation(self, item, duration):
ani = QPropertyAnimation(item, b'pos', self)
ani.setDuration(duration)
ani.setStartValue(item.pos())
width = self.squareWidth * 7
ani.setEndValue(QPointF(width - item.x(),
width - item.y()))
return ani
示例4: createAnimation
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
def createAnimation(self, target, index):
'''创建动画'''
# 暂停动画一
PauseAnimation1 = QPauseAnimation(target)
PauseAnimation1.setDuration(150 * index)
# 并行动画组一
# #透明度动画一
OpacityAnimation1 = QPropertyAnimation(target, b"opacity")
OpacityAnimation1.setDuration(400)
OpacityAnimation1.setStartValue(0)
OpacityAnimation1.setEndValue(1)
# #移动动画一
MoveAnimation1 = _MoveAnimation(target, self.parent, self.easing)
MoveAnimation1.setMoveType(_MoveAnimation.MOVE1)
MoveAnimation1.setDuration(400)
MoveAnimation1.setStartValue(QPoint(0, 0))
MoveAnimation1.setEndValue(QPoint(self.parent.width() / 4.0, 0))
# 添加到并行动画里面
ParallelAnimation1 = QParallelAnimationGroup()
ParallelAnimation1.addAnimation(OpacityAnimation1)
ParallelAnimation1.addAnimation(MoveAnimation1)
# 移动动画二
MoveAnimation2 = _MoveAnimation(target, self.parent, self.easing)
MoveAnimation2.setMoveType(_MoveAnimation.MOVE2)
MoveAnimation2.setDuration(2000)
MoveAnimation2.setEndValue(QPoint((self.parent.width() / 4.0) * 3.0, 0))
# 并行动画组二
# #透明度动画二
OpacityAnimation2 = QPropertyAnimation(target, b"opacity")
OpacityAnimation2.setDuration(400)
OpacityAnimation2.setStartValue(1)
OpacityAnimation2.setEndValue(0)
# #移动动画三
MoveAnimation3 = _MoveAnimation(target, self.parent, self.easing)
MoveAnimation3.setMoveType(_MoveAnimation.MOVE3)
MoveAnimation3.setDuration(400)
MoveAnimation3.setEndValue(QPoint(self.parent.width(), 0))
# 添加到并行动画里面
ParallelAnimation2 = QParallelAnimationGroup()
ParallelAnimation2.addAnimation(OpacityAnimation2)
ParallelAnimation2.addAnimation(MoveAnimation3)
# 暂停动画二
PauseAnimation2 = QPauseAnimation(target)
PauseAnimation2.setDuration(150 * (5 - index - 1))
# 串行动画组
self.setLoopCount(-1) # 无限循环
self.addAnimation(PauseAnimation1)
self.addAnimation(ParallelAnimation1)
self.addAnimation(MoveAnimation2)
self.addAnimation(ParallelAnimation2)
self.addAnimation(PauseAnimation2)
示例5: __init__
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
def __init__(self):
super(Robot, self).__init__()
self.setFlag(self.ItemHasNoContents)
self.torsoItem = RobotTorso(self)
self.headItem = RobotHead(self.torsoItem)
self.upperLeftArmItem = RobotLimb(self.torsoItem)
self.lowerLeftArmItem = RobotLimb(self.upperLeftArmItem)
self.upperRightArmItem = RobotLimb(self.torsoItem)
self.lowerRightArmItem = RobotLimb(self.upperRightArmItem)
self.upperRightLegItem = RobotLimb(self.torsoItem)
self.lowerRightLegItem = RobotLimb(self.upperRightLegItem)
self.upperLeftLegItem = RobotLimb(self.torsoItem)
self.lowerLeftLegItem = RobotLimb(self.upperLeftLegItem)
settings = (
# Item Position Rotation Scale
# x y start end
(self.headItem, 0, -18, 20, -20, 1.1),
(self.upperLeftArmItem, -15, -10, 190, 180, 0),
(self.lowerLeftArmItem, 30, 0, 50, 10, 0),
(self.upperRightArmItem, 15, -10, 300, 310, 0),
(self.lowerRightArmItem, 30, 0, 0, -70, 0),
(self.upperRightLegItem, 10, 32, 40, 120, 0),
(self.lowerRightLegItem, 30, 0, 10, 50, 0),
(self.upperLeftLegItem, -10, 32, 150, 80, 0),
(self.lowerLeftLegItem, 30, 0, 70, 10, 0),
(self.torsoItem, 0, 0, 5, -20, 0),
)
animation = QParallelAnimationGroup(self)
for item, pos_x, pos_y, start_rot, end_rot, scale in settings:
item.setPos(pos_x, pos_y)
rot_animation = QPropertyAnimation(item, b"rotation")
rot_animation.setStartValue(start_rot)
rot_animation.setEndValue(end_rot)
rot_animation.setEasingCurve(QEasingCurve.SineCurve)
rot_animation.setDuration(2000)
animation.addAnimation(rot_animation)
if scale > 0:
scale_animation = QPropertyAnimation(item, b"scale")
scale_animation.setEndValue(scale)
scale_animation.setEasingCurve(QEasingCurve.SineCurve)
scale_animation.setDuration(2000)
animation.addAnimation(scale_animation)
animation.setLoopCount(-1)
animation.start()
示例6: CircleObstruction
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
class CircleObstruction(QColorThemedGraphicsObject):
"""
Useful for notifications, I...guess?
"""
def get_thickness(self):
return self._thickness
def set_thickness(self,c):
self._thickness = c
self.update()
thickness = pyqtProperty(float, get_thickness, set_thickness)
def __init__(self, sz, thickness, parent=None):
super(CircleObstruction, self).__init__(parent)
self._sz = sz
self._thickness = thickness
self._color = Qt.blue
def boundingRect(self):
return QRectF(-self._thickness,
-self._thickness,
self._sz + 2*self._thickness,
self._sz + 2*self._thickness)
def paint(self, painter, option, widget):
# painter.setPen(QPen(self._color,
# self._thickness))
painter.setBrush(self._color)
painter.setPen(Qt.NoPen)
painter.drawEllipse(QRectF(
self._sz/2.0 - self._thickness,
self._sz/2.0 - self._thickness,
2*self._thickness,
2*self._thickness,
))
def show_anim(self):
self.anim = QPropertyAnimation(self, "thickness")
self.anim.setDuration(2000)
self.anim.setStartValue(self.get_thickness())
self.anim.setEndValue(50.0)
self.anim.setEasingCurve(QEasingCurve.OutElastic)
self.anim.start()
def hide_anim(self):
self.anim = QPropertyAnimation(self, "thickness")
self.anim.setDuration(500)
self.anim.setStartValue(self.get_thickness())
self.anim.setEndValue(0.0)
self.anim.setEasingCurve(QEasingCurve.InBack)
self.anim.start()
示例7: NotifyWidget
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
class NotifyWidget(QWidget):
def __init__(self):
super().__init__()
self.layout = QVBoxLayout(self)
self.sub_widget = _NotifySubWidget(self)
self.layout.addWidget(self.sub_widget)
self.layout.setContentsMargins(0, 0, 0, 0)
self._exit_shortcut = QShortcut(QKeySequence(Qt.Key_Escape), self)
self._exit_shortcut.activated.connect(self.close)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Tool)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setAttribute(Qt.WA_MacAlwaysShowToolWindow)
self.resize(width, height)
self.move(QApplication.desktop().width() - self.width() - 20, 40)
self.setLayout(self.layout)
self._animation = QPropertyAnimation(self, b'windowOpacity')
self._animation.setStartValue(0.8)
self._animation.setKeyValueAt(0.4, 1)
self._animation.setEndValue(0)
self._animation.setDuration(5000)
self._animation.finished.connect(self.close)
def show(self):
super().show()
self._animation.start()
def show_message(self, title, content, pixmap=None):
if not self.isVisible():
self.show()
self._animation.stop()
self._animation.setCurrentTime(0)
self._animation.start()
self.sub_widget.set_title(title)
self.sub_widget.set_content(content)
pixmap = pixmap if pixmap else QPixmap(WINDOW_ICON)
self.sub_widget.set_pixmap(pixmap)
def enterEvent(self, event):
self._animation.setCurrentTime(0)
示例8: animate
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
def animate(self, item, property_name, duration, start_value, end_value):
"""Summary
Args:
item (TYPE): Description
property_name (TYPE): Description
duration (TYPE): Description
start_value (TYPE): Description
end_value (TYPE): Description
"""
if item is not None:
b_name = property_name.encode('ascii')
anim = QPropertyAnimation(item.adapter, b_name)
anim.setDuration(duration)
anim.setStartValue(start_value)
anim.setEndValue(end_value)
anim.start()
item.adapter.saveRef(property_name, anim)
示例9: animate
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
def animate(self, item: QGraphicsItem,
property_name: str, duration: int,
start_value, end_value):
"""
Args:
item: Description
property_name: Description
duration: Description
start_value (QVariant): Description
end_value (QVariant): Description
"""
b_name = property_name.encode('ascii')
anim = item.adapter.getRef(property_name)
if anim is None:
anim = QPropertyAnimation(item.adapter, b_name)
item.adapter.saveRef(property_name, anim)
anim.setDuration(duration)
anim.setStartValue(start_value)
anim.setEndValue(end_value)
anim.start()
示例10: ChannelListItem
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
class ChannelListItem(QWidget):
"""
This class is responsible for managing the item in the list of channels.
The list item supports a fade-in effect, which can be enabled with the should_fade parameter in the constructor.
"""
def __init__(self, parent, channel, fade_delay=0, should_fade=False):
super(QWidget, self).__init__(parent)
uic.loadUi('qt_resources/channel_list_item.ui', self)
self.channel_name.setText(channel["name"])
self.channel_description_label.setText("Active 6 days ago • %d items" % channel["torrents"])
self.channel_num_subs_label.setText(str(channel["votes"]))
if channel["sub"]:
self.channel_subscribe_button.setText("✓ subscribed")
else:
self.channel_subscribe_button.setText("subscribe")
if should_fade:
self.opacity_effect = QGraphicsOpacityEffect(self)
self.opacity_effect.setOpacity(0)
self.setGraphicsEffect(self.opacity_effect)
self.timer = QTimer()
self.timer.setInterval(fade_delay)
self.timer.timeout.connect(self.fadeIn)
self.timer.start()
def fadeIn(self):
self.anim = QPropertyAnimation(self.opacity_effect, 'opacity')
self.anim.setDuration(800)
self.anim.setStartValue(0)
self.anim.setEndValue(1)
self.anim.start()
self.timer.stop()
示例11: ScreensharingToolbox
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
class ScreensharingToolbox(base_class, ui_class):
exposedPixels = 3
def __init__(self, parent):
super(ScreensharingToolbox, self).__init__(parent)
with Resources.directory:
self.setupUi()
parent.installEventFilter(self)
self.animation = QPropertyAnimation(self, 'pos')
self.animation.setDuration(250)
self.animation.setDirection(QPropertyAnimation.Forward)
self.animation.setEasingCurve(QEasingCurve.Linear) # or OutCirc with 300ms
self.retract_timer = QTimer(self)
self.retract_timer.setInterval(3000)
self.retract_timer.setSingleShot(True)
self.retract_timer.timeout.connect(self.retract)
self.resize(self.size().expandedTo(self.toolbox_layout.minimumSize()))
def setupUi(self):
super(ScreensharingToolbox, self).setupUi(self)
# fix the SVG icons, as the generated code loads them as pixmaps, losing their ability to scale -Dan
scale_icon = QIcon()
scale_icon.addFile(Resources.get('icons/scale.svg'), mode=QIcon.Normal, state=QIcon.Off)
viewonly_icon = QIcon()
viewonly_icon.addFile(Resources.get('icons/viewonly.svg'), mode=QIcon.Normal, state=QIcon.Off)
screenshot_icon = QIcon()
screenshot_icon.addFile(Resources.get('icons/screenshot.svg'), mode=QIcon.Normal, state=QIcon.Off)
fullscreen_icon = QIcon()
fullscreen_icon.addFile(Resources.get('icons/fullscreen.svg'), mode=QIcon.Normal, state=QIcon.Off)
fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Normal, state=QIcon.On)
fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Active, state=QIcon.On)
fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Disabled, state=QIcon.On)
fullscreen_icon.addFile(Resources.get('icons/fullscreen-exit.svg'), mode=QIcon.Selected, state=QIcon.On)
minimize_icon = QIcon()
minimize_icon.addFile(Resources.get('icons/minimize.svg'), mode=QIcon.Normal, state=QIcon.Off)
minimize_icon.addFile(Resources.get('icons/minimize-active.svg'), mode=QIcon.Active, state=QIcon.Off)
close_icon = QIcon()
close_icon.addFile(Resources.get('icons/close.svg'), mode=QIcon.Normal, state=QIcon.Off)
close_icon.addFile(Resources.get('icons/close-active.svg'), mode=QIcon.Active, state=QIcon.Off)
self.scale_action.setIcon(scale_icon)
self.viewonly_action.setIcon(viewonly_icon)
self.screenshot_action.setIcon(screenshot_icon)
self.fullscreen_action.setIcon(fullscreen_icon)
self.minimize_action.setIcon(minimize_icon)
self.close_action.setIcon(close_icon)
self.scale_button.setIcon(scale_icon)
self.viewonly_button.setIcon(viewonly_icon)
self.screenshot_button.setIcon(screenshot_icon)
self.fullscreen_button.setIcon(fullscreen_icon)
self.minimize_button.setIcon(minimize_icon)
self.close_button.setIcon(close_icon)
self.scale_button.setDefaultAction(self.scale_action)
self.viewonly_button.setDefaultAction(self.viewonly_action)
self.screenshot_button.setDefaultAction(self.screenshot_action)
self.fullscreen_button.setDefaultAction(self.fullscreen_action)
self.minimize_button.setDefaultAction(self.minimize_action)
self.close_button.setDefaultAction(self.close_action)
self.color_depth_button.clear()
self.color_depth_button.addItem('Default Color Depth', ServerDefault)
self.color_depth_button.addItem('TrueColor (24 bits)', TrueColor)
self.color_depth_button.addItem('HighColor (16 bits)', HighColor)
self.color_depth_button.addItem('LowColor (8 bits)', LowColor)
def eventFilter(self, watched, event):
if watched is self.parent() and event.type() == QEvent.Resize:
new_x = (watched.width() - self.width()) / 2
self.move(new_x, self.y())
self.animation.setStartValue(QPoint(new_x, -self.height() + self.exposedPixels))
self.animation.setEndValue(QPoint(new_x, 0))
return False
def enterEvent(self, event):
super(ScreensharingToolbox, self).enterEvent(event)
self.retract_timer.stop()
self.expose()
def leaveEvent(self, event):
super(ScreensharingToolbox, self).leaveEvent(event)
self.retract_timer.start()
def paintEvent(self, event): # make the widget style aware
option = QStyleOption()
option.initFrom(self)
painter = QStylePainter(self)
painter.drawPrimitive(QStyle.PE_Widget, option)
def expose(self):
if self.animation.state() == QPropertyAnimation.Running and self.animation.direction() == QPropertyAnimation.Forward:
return
elif self.animation.state() == QPropertyAnimation.Stopped and self.pos() == self.animation.endValue():
return
self.animation.setDirection(QPropertyAnimation.Forward)
self.animation.start()
def retract(self):
#.........这里部分代码省略.........
示例12: QPropertyAnimation
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
from PyQt5.QtCore import QPropertyAnimation, QEasingCurve
animation = QPropertyAnimation()
animation.setTargetObject()
animation.setStartValue(0)
animation.setEndValue(1000)
animation.setDuration(1000)
animation.setEasingCurve(QEasingCurve.InOutQuad)
animation.start()
示例13: MiniMap
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
class MiniMap(QPlainTextEdit):
def __init__(self, parent):
super(MiniMap, self).__init__(parent)
self.setWordWrapMode(QTextOption.NoWrap)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setReadOnly(True)
self.setCenterOnScroll(True)
self.setMouseTracking(True)
self.viewport().setCursor(Qt.PointingHandCursor)
self.setTextInteractionFlags(Qt.NoTextInteraction)
self._parent = parent
self.highlighter = None
self.lines_count = 0
if ACTIVATE_OPACITY:
self.goe = QGraphicsOpacityEffect()
self.setGraphicsEffect(self.goe)
self.goe.setOpacity(settings.MINIMAP_MIN_OPACITY)
self.animation = QPropertyAnimation(self.goe, b"opacity")
self.slider = SliderArea(self)
self.slider.show()
def __calculate_max(self):
line_height = self._parent.cursorRect().height()
if line_height > 0:
self.lines_count = self._parent.viewport().height() / line_height
self.slider.update_position()
self.update_visible_area()
def set_code(self, source):
self.setPlainText(source)
self.__calculate_max()
def adjust_to_parent(self):
self.setFixedHeight(self._parent.height())
self.setFixedWidth(self._parent.width() * settings.SIZE_PROPORTION)
x = self._parent.width() - self.width()
self.move(x, 0)
fontsize = int(self.width() / settings.MARGIN_LINE)
if fontsize < 1:
fontsize = 1
font = self.document().defaultFont()
font.setPointSize(fontsize)
self.setFont(font)
self.__calculate_max()
def update_visible_area(self):
if not self.slider.pressed:
line_number = self._parent.firstVisibleBlock().blockNumber()
block = self.document().findBlockByLineNumber(line_number)
cursor = self.textCursor()
cursor.setPosition(block.position())
rect = self.cursorRect(cursor)
self.setTextCursor(cursor)
self.slider.move_slider(rect.y())
def enterEvent(self, event):
if ACTIVATE_OPACITY:
self.animation.setDuration(300)
self.animation.setStartValue(settings.MINIMAP_MIN_OPACITY)
self.animation.setEndValue(settings.MINIMAP_MAX_OPACITY)
self.animation.start()
def leaveEvent(self, event):
if ACTIVATE_OPACITY:
self.animation.setDuration(300)
self.animation.setStartValue(settings.MINIMAP_MAX_OPACITY)
self.animation.setEndValue(settings.MINIMAP_MIN_OPACITY)
self.animation.start()
def mousePressEvent(self, event):
super(MiniMap, self).mousePressEvent(event)
cursor = self.cursorForPosition(event.pos())
self._parent.jump_to_line(cursor.blockNumber())
def resizeEvent(self, event):
super(MiniMap, self).resizeEvent(event)
self.slider.update_position()
def scroll_area(self, pos_parent, pos_slider):
pos_parent.setY(pos_parent.y() - pos_slider.y())
cursor = self.cursorForPosition(pos_parent)
self._parent.verticalScrollBar().setValue(cursor.blockNumber())
def wheelEvent(self, event):
super(MiniMap, self).wheelEvent(event)
self._parent.wheelEvent(event)
示例14: NS_Animate
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
class NS_Animate(object):
def __init__(self, scene, x_max, y_max, back_color):
scene = QGraphicsScene(0, 0, x_max, y_max)
scene.setBackgroundBrush(back_color)
color = [Qt.green, Qt.lightGray, Qt.darkYellow, QtGui.QColor.fromRgb(255, 85, 0)]
self.anim_butt = [ QGraphicsRectWidget(color[j]) for j in range(4) ]
for j in range(4):
scene.addItem(self.anim_butt[j])
self.window = QGraphicsView(scene)
self.window.setFrameStyle(0)
self.window.setAlignment(Qt.AlignLeft | Qt.AlignTop)
self.window.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.window.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.machine = QStateMachine()
self.group = QState()
self.timer = QTimer()
self.timer.setInterval(1250)
self.timer.setSingleShot(True)
self.group.entered.connect(self.timer.start)
# set states positions
anim_state_rects = [ [QRect(x_max*xp/6, y_max*yp/4, 8, 8) for xp in range(4)] for yp in range(4) ]
self.states = [ self.createGeometryState(
self.anim_butt[0], anim_state_rects[0][j], self.anim_butt[1], anim_state_rects[1][j],
self.anim_butt[2], anim_state_rects[2][j], self.anim_butt[3], anim_state_rects[3][j],
self.group
) for j in range(4) ]
self.group.setInitialState(self.states[0])
self.animationGroup = QParallelAnimationGroup()
self.anim = QPropertyAnimation(self.anim_butt[3], 'geometry')
self.anim.setDuration(1250)
self.anim.setEasingCurve(QEasingCurve.InBack)
self.animationGroup.addAnimation(self.anim)
self.subGroup = QSequentialAnimationGroup(self.animationGroup)
self.subGroup.addPause(100)
self.anim = QPropertyAnimation(self.anim_butt[2], 'geometry')
self.anim.setDuration(1000)
self.anim.setEasingCurve(QEasingCurve.OutElastic)
self.subGroup.addAnimation(self.anim)
self.subGroup = QSequentialAnimationGroup(self.animationGroup)
self.subGroup.addPause(500)
self.anim = QPropertyAnimation(self.anim_butt[1], 'geometry')
self.anim.setDuration(500)
self.anim.setEasingCurve(QEasingCurve.OutElastic)
self.subGroup.addAnimation(self.anim)
self.subGroup = QSequentialAnimationGroup(self.animationGroup)
self.subGroup.addPause(750)
self.anim = QPropertyAnimation(self.anim_butt[0], 'geometry')
self.anim.setDuration(250)
self.anim.setEasingCurve(QEasingCurve.OutElastic)
self.subGroup.addAnimation(self.anim)
self.stateSwitcher = StateSwitcher(self.machine)
self.group.addTransition(self.timer.timeout, self.stateSwitcher)
for j in range(4):
self.stateSwitcher.addState(self.states[j], self.animationGroup)
self.machine.addState(self.group)
self.machine.setInitialState(self.group)
self.machine.start()
#
def createGeometryState(self, w1, rect1, w2, rect2, w3, rect3, w4, rect4, parent):
result = QState(parent)
result.assignProperty(w1, 'geometry', rect1)
result.assignProperty(w1, 'geometry', rect1)
result.assignProperty(w2, 'geometry', rect2)
result.assignProperty(w3, 'geometry', rect3)
result.assignProperty(w4, 'geometry', rect4)
return result
示例15: CoffeeFundWindow
# 需要导入模块: from PyQt5.QtCore import QPropertyAnimation [as 别名]
# 或者: from PyQt5.QtCore.QPropertyAnimation import setDuration [as 别名]
class CoffeeFundWindow(QWidget):
signal_back = pyqtSignal()
signal_coffee = pyqtSignal()
signal_account = pyqtSignal()
def __init__(self, parent=None):
super().__init__()
self.cards = {} # type: Dict[GuiCards, QWidget]
"""
Python's GC will clean up QPropertyAnimations as soon as it leaves the button handler,
therefore they will appear not to work. Use members to store the animations.
see http://stackoverflow.com/a/6953965
"""
self.slide_in_animation = None
self.slide_out_animation = None
self.animation_group = None
self.setObjectName("coffeeFundWindow")
"""
Store the position and size of visible/hidden cards for the animation sequences
"""
self.hidden_geometry = None
self.visible_geometry = None
layout = QStackedLayout()
layout.setStackingMode(QStackedLayout.StackAll)
card_remove = RemoveCard()
self.cards[GuiCards.RemoveCard] = card_remove
layout.addWidget(card_remove)
card_choose_action = ChooseActionCard()
self.cards[GuiCards.ChooseAction] = card_choose_action
layout.addWidget(card_choose_action)
card_account = AccountCard()
self.cards[GuiCards.AccountInfo] = card_account
layout.addWidget(card_account)
# keep this as last initialized card, the last card will be shown on startup!
card_start = StartCard()
self.cards[GuiCards.Start] = card_start
layout.addWidget(card_start)
self.setLayout(layout)
self.setWindowTitle("Kaffeekasse")
layout.setCurrentWidget(card_start)
self.active_card = None
card_choose_action.button_account.clicked.connect(self.signal_account)
card_choose_action.button_coffee.clicked.connect(self.signal_coffee)
card_account.button_back.clicked.connect(self.signal_back)
def set_card_hidden(self, card: QWidget):
card.setGeometry(self.hidden_geometry)
def show_start(self):
self.show_card(GuiCards.Start)
def show_account(self, name, value):
self.cards[GuiCards.AccountInfo].set_user_name(name)
self.cards[GuiCards.AccountInfo].set_balance(value)
self.show_card(GuiCards.AccountInfo)
def show_choose_action(self, name: str):
self.cards[GuiCards.ChooseAction].set_user_name(name)
self.show_card(GuiCards.ChooseAction)
def show_remove(self):
self.show_card(GuiCards.RemoveCard)
def show_card(self, card_id: GuiCards):
if self.active_card is None:
self.active_card = self.cards[GuiCards.Start]
if self.active_card == self.cards[card_id]:
return
if self.visible_geometry is None or self.hidden_geometry is None:
self.visible_geometry = self.active_card.geometry() # type: QRect
self.hidden_geometry = QRect(self.visible_geometry.x(), self.visible_geometry.height() * 1.5,
self.visible_geometry.width(), self.visible_geometry.height())
for key in self.cards.keys():
if key != self.active_card:
self.set_card_hidden(self.cards[key])
card_to_show = self.cards[card_id]
self.start_card_switch(card_to_show)
self.active_card = self.cards[card_id]
self.layout().setCurrentWidget(self.active_card)
def start_card_switch(self, card_to_show):
self.slide_out_animation = QPropertyAnimation(self.active_card, "geometry")
self.slide_out_animation.setDuration(ANIMATION_DURATION)
self.slide_out_animation.setEasingCurve(QEasingCurve.OutCubic)
self.slide_out_animation.setStartValue(self.visible_geometry)
self.slide_out_animation.setEndValue(self.hidden_geometry)
self.set_card_hidden(card_to_show)
#.........这里部分代码省略.........