# -*- coding: utf-8 -*-
# @author: whitesev
# @time:   2021/3/17
# @desc:   PyQt5控件飞入效果实现
from PyQt5.Qt import QPropertyAnimation, QEasingCurve
from PyQt5.QtWidgets import QWidget, QFrame, QLabel, QApplication, QPushButton, QVBoxLayout
from PyQt5.QtCore import Qt, QRect
import sys

class myQt(QWidget):
    def __init__(self):
        super(myQt, self).__init__()
        self.resize(600, 600)
        self.setControls()  # 加载控件

    def setControls(self):
        vlayout = QVBoxLayout()
        btn_show = QPushButton()
        self.frame_prompt = QFrame(self)
        label = QLabel(self.frame_prompt)

        label.setText("这是个提示")
        label.setStyleSheet(
            "QLabel{background:#000000;color:#ffffff;font:16px SimHei;border-top-left-radius:5px;border-bottom-left-radius:5px;}")
        label.setAlignment(Qt.AlignCenter)
        btn_show.setText("点击显示提示")
        btn_show.clicked.connect(lambda: self.btnClickEvent())

        label.resize(150, 50)
        self.frame_prompt.resize(150, 50)
        self.frame_prompt.setGeometry(self.width() - self.frame_prompt.width(),
                                      self.height(),
                                      self.frame_prompt.width(),
                                      self.frame_prompt.height())

        vlayout.addWidget(btn_show)
        self.setLayout(vlayout)

    def btnClickEvent(self):
        anim = QPropertyAnimation(self.frame_prompt, b"geometry", self)
        anim.setDuration(6000)
        # 左边距 上边距  动画控件宽 动画控件高
        anim.setKeyValueAt(0, QRect(self.width() - self.frame_prompt.width(),
                                    self.height() + 1,
                                    self.frame_prompt.width(),
                                    self.frame_prompt.height()))
        anim.setKeyValueAt(0.5, QRect(self.width() - self.frame_prompt.width(),
                                      self.height() - self.frame_prompt.height(),
                                      self.frame_prompt.width(),
                                      self.frame_prompt.height()))
        anim.setKeyValueAt(0.85, QRect(self.width() - self.frame_prompt.width(),
                                       self.height() - self.frame_prompt.height(),
                                       self.frame_prompt.width(),
                                       self.frame_prompt.height()))
        anim.setKeyValueAt(1, QRect(self.width() - self.frame_prompt.width(),
                                    self.height() + 1,
                                    self.frame_prompt.width(),
                                    self.frame_prompt.height()))
        anim.setEasingCurve(QEasingCurve.OutCubic)
        anim.start(anim.DeleteWhenStopped)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    myqt = myQt()
    myqt.show()
    sys.exit(app.exec_())

演示图片

示例


负断只舟阡陌短,雨淋青瓦深巷中。