Python PyQt5.QtCore.QPropertyAnimation() Examples

The following are 30 code examples of PyQt5.QtCore.QPropertyAnimation(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .
Example #1
Source File: player.py    From MusicBox with MIT License 6 votes vote down vote up
def getDetailInfo(self):
        """点击后进行动画效果的: 显示某歌曲的详细信息。"""
        self.shortInfo.hide()
        self.detailInfo.show()

        self.showDetail = QPropertyAnimation(self, b"geometry")

        x = self.pos().x()
        y = self.pos().y()

        self.showDetail.setStartValue(QRect(x, y, self.width(), self.height()))
        # 获取顶层父窗口的长度。
        self.showDetail.setEndValue(QRect(0, self.grandparent.header.height()+3, self.grandparent.width(), self.grandparent.mainContent.height()))
        self.showDetail.setDuration(300)
        self.showDetail.setEasingCurve(QEasingCurve.InBack)

        self.showDetail.start(QAbstractAnimation.DeleteWhenStopped)
        # 将该组件显示在最前,默认会嵌入到父组件里面。
        self.raise_()

        self.setDetailInfo() 
Example #2
Source File: player.py    From MusicBox with MIT License 6 votes vote down vote up
def getShortInfo(self):
        """返回到原来的缩略图信息。"""
        self.detailInfo.hide()
        self.showShort = QPropertyAnimation(self, b"geometry")
        
        x = self.pos().x()
        y = self.pos().y()
        
        self.showShort.setStartValue(QRect(0, self.grandparent.header.height(), self.grandparent.width(), self.grandparent.mainContent.height()))
        self.showShort.setEndValue(QRect(0, self.grandparent.height()-64-self.parent.height(), self.grandparent.navigation.width(), 64))
        self.showShort.setDuration(300)
        self.showShort.setEasingCurve(QEasingCurve.InBack)
        
        self.showShort.start(QAbstractAnimation.DeleteWhenStopped)

        self.shortInfo.show()
        self.raise_() 
Example #3
Source File: qt.py    From imperialism-remake with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent):
        """
        Create property animations, sets the opacity to zero initially.

        :param parent:
        """
        super().__init__()
        if isinstance(parent, QtWidgets.QGraphicsItem):
            # create opacity effect
            self.effect = QtWidgets.QGraphicsOpacityEffect()
            self.effect.setOpacity(0)
            parent.setGraphicsEffect(self.effect)
            self.fade = QtCore.QPropertyAnimation(self.effect, 'opacity'.encode())  # encode is utf-8 by default
        elif isinstance(parent, QtWidgets.QWidget):
            parent.setWindowOpacity(0)
            self.fade = QtCore.QPropertyAnimation(parent, 'windowOpacity'.encode())  # encode is utf-8 by default
        else:
            raise RuntimeError('Type of parameter must be QtWidgets.QGraphicsItem or QtWidgets.QWidget.')

        # set start and stop value
        self.fade.setStartValue(0)
        self.fade.setEndValue(1)
        self.fade.finished.connect(self.finished)

        self.forward = True 
Example #4
Source File: tankity_tank_tank_tank.py    From Mastering-GUI-Programming-with-Python with MIT License 6 votes vote down vote up
def __init__(self, y_pos, up=True):
        super().__init__()
        self.up = up
        self.y_pos = y_pos

        # For fun, let's blur the object
        blur = qtw.QGraphicsBlurEffect()
        blur.setBlurRadius(10)
        blur.setBlurHints(
            qtw.QGraphicsBlurEffect.AnimationHint)
        self.setGraphicsEffect(blur)

        # Animate the object
        self.animation = qtc.QPropertyAnimation(self, b'y')
        self.animation.setStartValue(y_pos)
        end = 0 if up else SCREEN_HEIGHT
        self.animation.setEndValue(end)
        self.animation.setDuration(1000)
        self.yChanged.connect(self.check_collision) 
Example #5
Source File: CDrawer.py    From CustomWidgets with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, stretch=1 / 3, direction=0, widget=None, **kwargs):
        super(CDrawer, self).__init__(*args, **kwargs)
        self.setWindowFlags(self.windowFlags(
        ) | Qt.FramelessWindowHint | Qt.Popup | Qt.NoDropShadowWindowHint)
        self.setAttribute(Qt.WA_StyledBackground, True)
        self.setAttribute(Qt.WA_TranslucentBackground, True)
        # 进入动画
        self.animIn = QPropertyAnimation(
            self, duration=500, easingCurve=QEasingCurve.OutCubic)
        self.animIn.setPropertyName(b'pos')
        # 离开动画
        self.animOut = QPropertyAnimation(
            self, duration=500, finished=self.onAnimOutEnd,
            easingCurve=QEasingCurve.OutCubic)
        self.animOut.setPropertyName(b'pos')
        self.animOut.setDuration(500)
        self.setStretch(stretch)        # 占比
        self.direction = direction      # 方向
        # 半透明背景
        self.alphaWidget = QWidget(
            self, objectName='CDrawer_alphaWidget',
            styleSheet='#CDrawer_alphaWidget{background:rgba(55,55,55,100);}')
        self.alphaWidget.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.setWidget(widget)          # 子控件 
Example #6
Source File: screens.py    From tinydecred with ISC License 6 votes vote down vote up
def setFadeIn(self, v):
        """
        Set the screen to use a fade-in animation.

        Args:
            v (bool): If True, run the fade-in animation when its trigger is
                received. False will disable the animation.
        """
        if not v:
            self.animations.pop(FADE_IN_ANIMATION, None)
            return
        effect = QtWidgets.QGraphicsOpacityEffect(self)
        self.animations[FADE_IN_ANIMATION] = a = QtCore.QPropertyAnimation(
            effect, b"opacity"
        )
        a.setDuration(550)
        a.setStartValue(0)
        a.setEndValue(1)
        a.setEasingCurve(QtCore.QEasingCurve.OutQuad)
        self.setGraphicsEffect(effect) 
Example #7
Source File: widgets.py    From gridsync with GNU General Public License v3.0 6 votes vote down vote up
def decrypt_content(self, data, password):
        self.progress = QProgressDialog("Trying to decrypt...", None, 0, 100)
        self.progress.show()
        self.animation = QPropertyAnimation(self.progress, b"value")
        self.animation.setDuration(5000)  # XXX
        self.animation.setStartValue(0)
        self.animation.setEndValue(99)
        self.animation.start()
        self.crypter = Crypter(data, password.encode())
        self.crypter_thread = QThread()
        self.crypter.moveToThread(self.crypter_thread)
        self.crypter.succeeded.connect(self.animation.stop)
        self.crypter.succeeded.connect(self.progress.close)
        self.crypter.succeeded.connect(self.on_decryption_succeeded)
        self.crypter.failed.connect(self.animation.stop)
        self.crypter.failed.connect(self.progress.close)
        self.crypter.failed.connect(self.on_decryption_failed)
        self.crypter_thread.started.connect(self.crypter.decrypt)
        self.crypter_thread.start() 
Example #8
Source File: qutilities.py    From tinydecred with ISC License 5 votes vote down vote up
def __init__(
        self, callback,
    ):
        """
        Args:
            callback func(bool): The callback function will receive the current
                state after it is changed due to a click.
        """
        super().__init__()
        self.callback = callback
        self.onBrush = QtGui.QBrush(QtGui.QColor("#569167"))
        self.slotBrush = QtGui.QBrush(QtGui.QColor("#999999"))
        self.switchBrush = self.slotBrush
        self.disabledBrush = QtGui.QBrush(QtGui.QColor("#666666"))
        self.on = False
        self.fullHeight = 18
        self.halfHeight = self.xPos = self.fullHeight / 2
        self.fullWidth = 34
        self.setFixedWidth(self.fullWidth)
        self.slotMargin = 3
        self.slotHeight = self.fullHeight - 2 * self.slotMargin
        self.travel = self.fullWidth - self.fullHeight
        self.slotRect = QtCore.QRect(
            self.slotMargin,
            self.slotMargin,
            self.fullWidth - 2 * self.slotMargin,
            self.slotHeight,
        )
        self.animation = QtCore.QPropertyAnimation(self, b"pqProp", self)
        self.animation.setDuration(120)
        self.setCursor(QtCore.Qt.PointingHandCursor) 
Example #9
Source File: ButtomZoom.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(ZoomButton, self).__init__(*args, **kwargs)
        self._animation = QPropertyAnimation(
            self, b'geometry', self, duration=200) 
Example #10
Source File: AnimationShadowEffect.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, color, *args, **kwargs):
        super(AnimationShadowEffect, self).__init__(*args, **kwargs)
        self.setColor(color)
        self.setOffset(0, 0)
        self.setBlurRadius(0)
        self._radius = 0
        self.animation = QPropertyAnimation(self)
        self.animation.setTargetObject(self)
        self.animation.setDuration(2000)  # 一次循环时间
        self.animation.setLoopCount(-1)  # 永久循环
        self.animation.setPropertyName(b'radius')
        # 插入值
        self.animation.setKeyValueAt(0, 1)
        self.animation.setKeyValueAt(0.5, 30)
        self.animation.setKeyValueAt(1, 1) 
Example #11
Source File: ShakeWindow.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def doShakeWindow(self, target):
        """窗口抖动动画
        :param target:        目标控件
        """
        if hasattr(target, '_shake_animation'):
            # 如果已经有该对象则跳过
            return

        animation = QPropertyAnimation(target, b'pos', target)
        target._shake_animation = animation
        animation.finished.connect(lambda: delattr(target, '_shake_animation'))

        pos = target.pos()
        x, y = pos.x(), pos.y()

        animation.setDuration(200)
        animation.setLoopCount(2)
        animation.setKeyValueAt(0, QPoint(x, y))
        animation.setKeyValueAt(0.09, QPoint(x + 2, y - 2))
        animation.setKeyValueAt(0.18, QPoint(x + 4, y - 4))
        animation.setKeyValueAt(0.27, QPoint(x + 2, y - 6))
        animation.setKeyValueAt(0.36, QPoint(x + 0, y - 8))
        animation.setKeyValueAt(0.45, QPoint(x - 2, y - 10))
        animation.setKeyValueAt(0.54, QPoint(x - 4, y - 8))
        animation.setKeyValueAt(0.63, QPoint(x - 6, y - 6))
        animation.setKeyValueAt(0.72, QPoint(x - 8, y - 4))
        animation.setKeyValueAt(0.81, QPoint(x - 6, y - 2))
        animation.setKeyValueAt(0.90, QPoint(x - 4, y - 0))
        animation.setKeyValueAt(0.99, QPoint(x - 2, y + 2))
        animation.setEndValue(QPoint(x, y))

        animation.start(animation.DeleteWhenStopped) 
Example #12
Source File: FadeInOut.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)
        self.resize(400, 400)
        layout = QVBoxLayout(self)
        layout.addWidget(QPushButton('退出', self, clicked=self.doClose))

        # 窗口透明度动画类
        self.animation = QPropertyAnimation(self, b'windowOpacity')
        self.animation.setDuration(1000)  # 持续时间1秒

        # 执行淡入
        self.doShow() 
Example #13
Source File: MenuAnimation.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def initAnimation(self):
        # 按钮动画
        self._animation = QPropertyAnimation(
            self._contextMenu, b'geometry', self,
            easingCurve=QEasingCurve.Linear, duration=300)
        # easingCurve 修改该变量可以实现不同的效果 
Example #14
Source File: FontRotate.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(PushButtonFont, self).__init__(*args, **kwargs)
        self.fontSize = self.font().pointSize() * 2
        self._rotateAnimationStarted = False
        self._rotateAnimation = QPropertyAnimation(self)
        self._rotateAnimation.setTargetObject(self)
        self._rotateAnimation.setStartValue(1)
        self._rotateAnimation.setEndValue(12)
        self._rotateAnimation.setDuration(1000)
        self._rotateAnimation.setLoopCount(-1)  # 无限循环
        self._rotateAnimation.valueChanged.connect(self.update)
        self.clicked.connect(self._onClick) 
Example #15
Source File: recovery.py    From gridsync with GNU General Public License v3.0 5 votes vote down vote up
def _decrypt_content(self, data, password):
        logging.debug("Trying to decrypt %s...", self.filepath)
        self.progress = QProgressDialog(
            "Trying to decrypt {}...".format(os.path.basename(self.filepath)),
            None,
            0,
            100,
        )
        self.progress.show()
        self.animation = QPropertyAnimation(self.progress, b"value")
        self.animation.setDuration(6000)  # XXX
        self.animation.setStartValue(0)
        self.animation.setEndValue(99)
        self.animation.start()
        self.crypter = Crypter(data, password.encode())
        self.crypter_thread = QThread()
        self.crypter.moveToThread(self.crypter_thread)
        self.crypter.succeeded.connect(self.animation.stop)
        self.crypter.succeeded.connect(self.progress.close)
        self.crypter.succeeded.connect(self._on_decryption_succeeded)
        self.crypter.failed.connect(self.animation.stop)
        self.crypter.failed.connect(self.progress.close)
        self.crypter.failed.connect(self._on_decryption_failed)
        self.crypter_thread.started.connect(self.crypter.decrypt)
        self.crypter_thread.start() 
Example #16
Source File: tankity_tank_tank_tank.py    From Mastering-GUI-Programming-with-Python with MIT License 5 votes vote down vote up
def toggle_direction(self):
        if self.animation.direction() == qtc.QPropertyAnimation.Forward:
            self.left()
        else:
            self.right() 
Example #17
Source File: qutilities.py    From tinydecred with ISC License 5 votes vote down vote up
def setOffset(self, o):
        """
        Setter for QPropertyAnimation.
        """
        self.xPos = o
        self.update() 
Example #18
Source File: qutilities.py    From tinydecred with ISC License 5 votes vote down vote up
def getOffset(self):
        """
        Getter for QPropertyAnimation.
        """
        return self.xPos 
Example #19
Source File: main.py    From python-examples with MIT License 5 votes vote down vote up
def doAnimation_1(self):
        self.anim = QPropertyAnimation(self.frame, b"geometry")
        self.anim.setDuration(1000)
        self.anim.setStartValue(QRect(0, 0, 100, 100))
        self.anim.setEndValue(QRect(300, 0, 100, 100))

        self.anim.finished.connect(self.doAnimation_2)
 
        self.anim.start() 
Example #20
Source File: main.py    From python-examples with MIT License 5 votes vote down vote up
def doAnimation_2(self):
        self.anim = QPropertyAnimation(self.frame, b"geometry")
        self.anim.setDuration(1000)
        self.anim.setStartValue(QRect(300, 0, 100, 100))
        self.anim.setEndValue(QRect(300, 300, 100, 100))

        self.anim.finished.connect(self.doAnimation_3)
 
        self.anim.start() 
Example #21
Source File: main.py    From python-examples with MIT License 5 votes vote down vote up
def doAnimation_3(self):
        self.anim = QPropertyAnimation(self.frame, b"geometry")
        self.anim.setDuration(1000)
        self.anim.setStartValue(QRect(300, 300, 100, 100))
        self.anim.setEndValue(QRect(0, 300, 100, 100))

        self.anim.finished.connect(self.doAnimation_4)
 
        self.anim.start() 
Example #22
Source File: main.py    From python-examples with MIT License 5 votes vote down vote up
def doAnimation_4(self):
        self.anim = QPropertyAnimation(self.frame, b"geometry")
        self.anim.setDuration(1000)
        self.anim.setStartValue(QRect(0, 300, 100, 100))
        self.anim.setEndValue(QRect(0, 0, 100, 100))

        self.anim.finished.connect(self.doAnimation_1)
 
        self.anim.start() 
Example #23
Source File: collapsiblebox.py    From asammdf with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, title="", parent=None):
        super(CollapsibleBox, self).__init__(parent)

        self.toggle_button = QtWidgets.QToolButton(
            text=title, checkable=True, checked=False
        )
        self.toggle_button.setStyleSheet("QToolButton { border: none; }")
        self.toggle_button.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
        self.toggle_button.setArrowType(QtCore.Qt.RightArrow)
        self.toggle_button.pressed.connect(self.on_pressed)

        self.toggle_animation = QtCore.QParallelAnimationGroup(self)

        self.content_area = QtWidgets.QScrollArea(maximumHeight=0, minimumHeight=0)
        self.content_area.setSizePolicy(
            QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed
        )
        self.content_area.setFrameShape(QtWidgets.QFrame.NoFrame)

        lay = QtWidgets.QVBoxLayout(self)
        lay.setSpacing(0)
        lay.setContentsMargins(0, 0, 0, 0)
        lay.addWidget(self.toggle_button)
        lay.addWidget(self.content_area)

        self.toggle_animation.addAnimation(
            QtCore.QPropertyAnimation(self, b"minimumHeight")
        )
        self.toggle_animation.addAnimation(
            QtCore.QPropertyAnimation(self, b"maximumHeight")
        )
        self.toggle_animation.addAnimation(
            QtCore.QPropertyAnimation(self.content_area, b"maximumHeight")
        ) 
Example #24
Source File: interruptorPalanca.py    From PyQt5 with MIT License 5 votes vote down vote up
def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.mover.setY(1)
            
            if event.pos().x() < Frame.VALOR / 2:
                self.mover.setX(Frame.MIN_VALOR)
            elif event.pos().x() > Frame.VALOR / 2:
                self.mover.setX(Frame.MAX_VALOR - self.parent.button.width())

            self.animacion = QPropertyAnimation(self.parent.button, b"pos")
            self.animacion.setDuration(150)
            self.animacion.setEndValue(self.mover)
            self.animacion.valueChanged.connect(self.actualizarEstado)
            self.animacion.finished.connect(self.emitirEstado)
            self.animacion.start(QAbstractAnimation.DeleteWhenStopped) 
Example #25
Source File: instrument_srs.py    From gdb_python_api with MIT License 5 votes vote down vote up
def _perform_move(self, a, pos):
        from PyQt5.QtCore import QPropertyAnimation
        # create animation for this move operation
        anim = QPropertyAnimation(a, b'pos')
        anim.setDuration(200)
        anim.setEndValue(pos)
        anim.start()
        # the QPropertyAnimation object must outlive this method, so we attach it to this instance
        # TODO we should really collect it afterwards, perhaps with a handler for the finished() signal...
        self.animations.append(anim) 
Example #26
Source File: instrument_srs.py    From gdb_python_api with MIT License 5 votes vote down vote up
def _perform_swap(self, a, b):
        from PyQt5.QtCore import QPointF, QPropertyAnimation

        elt_a = self.elements[a]
        elt_b = self.elements[b]
        # update positions
        pos_a = elt_a.pos
        pos_b = elt_b.pos

        # animate the exchange: move in an arc above/below a point halfway between
        pos_between = (pos_a + pos_b) / 2
        pos_above = QPointF(pos_between.x(), -10)
        pos_below = QPointF(pos_between.x(), 50)
        anim_a = QPropertyAnimation(self.elements[a], b'pos')
        anim_b = QPropertyAnimation(self.elements[b], b'pos')
        anim_a.setDuration(400)
        anim_b.setDuration(400)
        anim_a.setKeyValueAt(0.5, pos_above)
        anim_b.setKeyValueAt(0.5, pos_below)
        anim_a.setKeyValueAt(1, pos_b)
        anim_b.setKeyValueAt(1, pos_a)
        anim_a.start()
        anim_b.start()
        self.animations.append(anim_a)
        self.animations.append(anim_b)

        # update elements list
        self.elements[a] = elt_b
        self.elements[b] = elt_a 
Example #27
Source File: dockwidgets.py    From Lector with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, main_window, notes_only, contentView, parent=None):
        super(PliantDockWidget, self).__init__(parent)
        self.main_window = main_window
        self.notes_only = notes_only
        self.contentView = contentView
        self.current_annotation = None
        self.parent = parent

        # Models
        # The following models belong to the sideDock
        # bookmarkModel, bookmarkProxyModel
        # annotationModel
        # searchResultsModel
        self.bookmarkModel = None
        self.bookmarkProxyModel = None
        self.annotationModel = None
        self.searchResultsModel = None

        # References
        # All widgets belong to these
        self.bookmarks = None
        self.annotations = None
        self.search = None

        # Widgets
        # Except this one
        self.sideDockTabWidget = None

        # Animate appearance
        self.animation = QtCore.QPropertyAnimation(self, b'windowOpacity')
        self.animation.setStartValue(0)
        self.animation.setEndValue(1)
        self.animation.setDuration(200) 
Example #28
Source File: WindowWithTitleBar.py    From QCandyUi with MIT License 5 votes vote down vote up
def showTip(self, text, color='#20c3ff'):
        if self.tipLabel is not None:
            self.tipLabel.show()
            self.tipLabel.setStyleSheet(
                "QLabel{background: %s;border:3px; color: #FFFFFF; border-radius: 5px}" % color)
            self.tipLabel.setText(text)
            eff = QGraphicsOpacityEffect(self)
            self.tipLabel.setGraphicsEffect(eff)
            self.animate = QPropertyAnimation(eff, "opacity")
            self.animate.setDuration(2000)
            self.animate.setStartValue(0.8)
            self.animate.setEndValue(0)
            self.animate.setEasingCurve(QEasingCurve.InCubic)
            self.animate.finished.connect(lambda: self.tipLabel.hide())
            self.animate.start() 
Example #29
Source File: switch_button.py    From parsec-cloud with GNU Affero General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, event):  # pylint: disable=invalid-name
        super().mouseReleaseEvent(event)
        if event.button() == Qt.LeftButton:
            anim = QPropertyAnimation(self, b"offset", self)
            anim.setDuration(120)
            anim.setStartValue(self.offset)
            anim.setEndValue(self._end_offset[self.isChecked()]())
            anim.start() 
Example #30
Source File: login.py    From lanzou-gui with MIT License 5 votes vote down vote up
def change_show_input_cookie(self):
        row_c = 4 if is_windows else 3
        if self.form.rowCount() < row_c:
            self.org_height = self.height()
            self.form.addRow(self.cookie_lb, self.cookie_ed)
            self.show_input_cookie_btn.setText("隐藏Cookie输入框")
            self.change_height = None
            self.adjustSize()
        else:
            if not self.change_height:
                self.change_height = self.height()
            if self.cookie_ed.isVisible():
                self.cookie_lb.setVisible(False)
                self.cookie_ed.setVisible(False)
                self.show_input_cookie_btn.setText("显示Cookie输入框")
                start_height, end_height = self.change_height, self.org_height
            else:
                self.cookie_lb.setVisible(True)
                self.cookie_ed.setVisible(True)
                self.show_input_cookie_btn.setText("隐藏Cookie输入框")
                start_height, end_height = self.org_height, self.change_height
            gm = self.geometry()
            x, y = gm.x(), gm.y()
            wd = self.width()
            self.animation = QPropertyAnimation(self, b'geometry')
            self.animation.setDuration(400)
            self.animation.setStartValue(QRect(x, y, wd, start_height))
            self.animation.setEndValue(QRect(x, y, wd, end_height))
            self.animation.start()