属性动画QPropertyAnimation

继承于 QAbstractAnimation-->QVariantAnimation-->QPropertyAnimation

改变大小、颜色或位置是动画中的常见操作,而QPropertyAnimation类可以修改控件的属性值

from PyQt5.QtWidgets import QApplication, QWidget,QPushButton
import sys
from PyQt5.QtCore import QPropertyAnimation,QPoint,QSize,QRect,QEasingCurve class win(QWidget):
def __init__(self):
super().__init__()
self.resize(400,400)
self.setWindowTitle('动画学习') btn=QPushButton('按钮',self)
btn.move(100,100)
btn.resize(100,100)
btn.setStyleSheet('background-color:yellow')
#ani=QPropertyAnimation(btn,b'pos',self) #创建动画对象
ani = QPropertyAnimation(self) #创建动画对象
ani.setTargetObject(btn) #设置动画目标对象
#ani.setTargetObject(self)
ani.setPropertyName(b'pos') #设置动画属性
#注意:字节类型
#pos---位置动画---QPoint
#size---大小动画---QSize
#geometry----位置+大小动画----QRect
#windowOpacity---窗口的透明度(0.0是透明的 1.0是不透明)---好像只适合顶层窗口

ani.setStartValue(QPoint(0,0)) #设置开始位置---按钮的左上角位置

ani.setEndValue(QPoint(300,300)) #设置结束位置
#ani.setStartValue(QSize(0, 0)) # 设置开始大小
#ani.setEndValue(QSize(300, 300)) # 设置结束大小
#ani.setStartValue(QRect(0, 0,100,100)) # 设置开始位置和大小
#ani.setEndValue(QRect(100,100,300, 300)) # 设置结束位置和大小 #ani.setStartValue(1) # 设置开始不透明
#ani.setKeyValueAt(0.5,0.2)#在动画的某时间点插入一个值
#参数1 0.0到1.0 0.0表示开始点,1.0表示结束点
#在动画的中间插入透明度0.2
#ani.setKeyValueAt(1, 1) #在动画的结束点是不透明的 #ani.setEndValue(0) # 设置结束透明
ani.setDuration(5000) #设置动画单次时长---单位毫秒

ani.setEasingCurve(QEasingCurve.InQuad) #设置动画的节奏

#取值 https://doc.qt.io/qt-5/qeasingcurve.html#Type-enum

ani.start() #动画开始---非阻塞
if __name__=='__main__':
app=QApplication(sys.argv)
w=win()
w.show()
sys.exit(app.exec_())

属性动画的父类功能

from PyQt5.QtWidgets import QApplication, QWidget,QPushButton
import sys
from PyQt5.QtCore import QPropertyAnimation,QPoint,QSize,QRect,QEasingCurve,QAbstractAnimation class win(QWidget):
def __init__(self):
super().__init__()
self.resize(400,400)
self.setWindowTitle('动画学习') btn=QPushButton('按钮',self)
btn.move(100,100)
btn.resize(100,100)
btn.setStyleSheet('background-color:yellow')
btn.clicked.connect(self.AA)
btn1 = QPushButton('暂停', self)
btn1.clicked.connect(self.BB)
btn1.move(10,150)
btn2 = QPushButton('恢复暂停', self)
btn2.clicked.connect(self.CC)
btn2.move(10, 200)
btn3 = QPushButton('停止', self)
btn3.clicked.connect(self.DD)
btn3.move(10, 250)
btn4 = QPushButton('设置时间', self)
btn4.clicked.connect(self.EE)
btn4.move(10, 300) ani = QPropertyAnimation(self)
self.ani=ani
ani.setTargetObject(btn)
ani.setPropertyName(b'pos')
ani.setStartValue(QPoint(0,0))
ani.setEndValue(QPoint(300,300))
ani.setDuration(5000)
ani.setEasingCurve(QEasingCurve.InQuad)
ani.setLoopCount(3) #设置动画次数---默认1次
ani.setDirection(QAbstractAnimation.Forward) #设置动画方向
#QAbstractAnimation.Backward=1 动画的当前时间随着时间减少(即,从结束/持续时间向0移动)---倒序
#QAbstractAnimation.Forward=0 动画的当前时间随着时间而增加(即,从0移动到结束/持续时间)---顺序 #信号
ani.currentLoopChanged.connect(self.FF) #循环遍数发生变化时
#会向槽函数传递一个参数---当前循环的遍数 #directionChanged(QAbstractAnimation.Direction newDirection) 动画方向发生改变时
#会向槽函数传递一个参数---动画新方向

ani.finished.connect(self.HH) #动画完成时


ani.stateChanged.connect(self.GG) #状态发生改变时

# 会向槽函数传递两个参数---新状态和老状态 ani.start() #启动动画
#参数 QAbstractAnimation.KeepWhenStopped 停止时不会删除动画
# QAbstractAnimation.DeleteWhenStopped 停止时动画将自动删除 def AA(self):
s=self.ani.loopCount() #返回动画总循环次数
print('动画总循环次数',s)
s = self.ani.currentLoop() # 返回当前是循环中的第几次---0次开始
#如果setDirection设置为倒序,返回值也是倒序
print('当前次数是:', s)
s = self.ani.duration() #返回单次时长
print('单次时长是:', s)
s = self.ani.currentLoopTime() # 当前单次循环内的时间
# 如果setDirection设置为倒序,返回值也是倒序
print('当前单次循环内的时间是:', s)
s = self.ani.currentTime() #当前总循环中时长
#如果setDirection设置为倒序,返回值也是倒序
print('当前总循环内时长是:', s)
s=self.ani.direction() #返回动画方向
# 返回值 int
#1 表示倒序;0 表示 顺序
print('动画方向:',s) def BB(self):
#self.ani.pause() #暂停
self.ani.setPaused(True) #是否暂停
s=self.ani.State() #返回动画的状态
#QAbstractAnimation.Paused=1 暂停状态
#QAbstractAnimation.Stopped=0 停止状态
#QAbstractAnimation.Running=2 运行状态
print(s) def CC(self):
#self.ani.resume() #恢复暂停--继续
self.ani.setPaused(False) # 是否暂停
s = self.ani.State() # 返回动画的状态
print(s) def DD(self):
self.ani.stop() #停止 def EE(self):
self.ani.setCurrentTime(14000) #设置当前动画时间--按总时长计算--毫秒 def FF(self,n):
print('当前循环遍数是:',n) def HH(self):
print('动画播放完毕') def GG(self,z,z1):
print('新状态是:',z)
print('老状态是:',z1) if __name__=='__main__':
app=QApplication(sys.argv)
w=win()
w.show()
sys.exit(app.exec_())

天子骄龙

属性动画QPropertyAnimation的更多相关文章

  1. Android动画效果之Property Animation进阶(属性动画)

    前言: 前面初步认识了Android的Property Animation(属性动画)Android动画效果之初识Property Animation(属性动画)(三),并且利用属性动画简单了补间动画 ...

  2. Android动画效果之初识Property Animation(属性动画)

    前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...

  3. Android属性动画

    这几天看郭神的博客 Android属性动画完全解析(上),初识属性动画的基本用法之后,我自己突然想实现一种动画功能,就是我们在携程网.阿里旅行等等手机APP端买火车票的时候,看到有选择城市,那么就有出 ...

  4. Android动画:模拟开关按钮点击打开动画(属性动画之平移动画)

    在Android里面,一些炫酷的动画确实是很吸引人的地方,让然看了就赏心悦目,一个好看的动画可能会提高用户对软件的使用率.另外说到动画,在Android里面支持3种动画: 逐帧动画(Frame Ani ...

  5. android 帧动画,补间动画,属性动画的简单总结

      帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...

  6. View动画和属性动画

    在应用中, 动画效果提升用户体验, 主要分为View动画和属性动画. View动画变换场景图片效果, 效果包括平移(translate), 缩放(scale), 旋转(rotate), 透明(alph ...

  7. Android属性动画源代码解析(超详细)

    本文假定你已经对属性动画有了一定的了解,至少使用过属性动画.下面我们就从属性动画最简单的使用开始. ObjectAnimator .ofInt(target,propName,values[]) .s ...

  8. ObjectAnimator属性动画应用demo

    感谢慕课网--eclipse_xu 布局文件:activity_main.xml <FrameLayout xmlns:android="http://schemas.android. ...

  9. 使用属性动画 — Property Animation

    属性动画,就是通过控制对象中的属性值产生的动画.属性动画是目前最高级的2D动画系统. 在API Level 11中添加.Property Animation号称能控制一切对象的动画,包括可见的和不可见 ...

随机推荐

  1. Test Scenarios for Filter Criteria

    1 User should be able to filter results using all parameters on the page2 refine search functionalit ...

  2. Centos 7最小化安装后配置

    关闭SELINUX vi /etc/sysconfig/selinux SELINUX=disabled :wq 配置网卡(最小化安装后ifconfig无法使用),该配置的前提是采用 NAT模式 vi ...

  3. Quartz.NET 前一次任务未执行完成时不触发下次的解决方法

    如图所示,在Job 上 加     [DisallowConcurrentExecution]        特性

  4. 一本通1530 Ant Trip

    1530:Ant Trip [题目描述] 原题来自:2009 Multi-University Training Contest 12 - Host by FZU 给你无向图的 N 个点和 M 条边, ...

  5. [代码]--c#-实现局域网聊天

    服务器端: using System; using System.Collections.Generic; using System.Linq; using System.Net; using Sys ...

  6. filebeat 配置文件参数

      filebeat 配置 所有的 beats 组件在 output 方面的配置都是一致的,之前章节已经介绍过.这里只介绍 filebeat 在 input 段的配置,如下: filebeat: sp ...

  7. linux 运维常用的一些命令收集

    1.删除0字节文件find -type f -size 0 -exec rm -rf {} ; 2.查看进程按内存从大到小排列ps -e   -o “%C   : %p : %z : %a”|sort ...

  8. 【Luogu4723】线性递推(常系数齐次线性递推)

    [Luogu4723]线性递推(常系数齐次线性递推) 题面 洛谷 题解 板子题QwQ,注意多项式除法那里每个多项式的系数,调了一天. #include<iostream> #include ...

  9. protobuf for java

    本文档为java编程人员使用protocol buffer提供了一个基本的介绍,通过一个简单的例程进行介绍.通过本文,你可以了解到如下信息: 1.在一个.proto文件中定义一个信息格式. 2.使用p ...

  10. [luogu1327][生活大爆炸石头剪子布]

    题目地址 https://www.luogu.org/problemnew/show/P1328 题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负. ...