属性动画QPropertyAnimation
属性动画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的更多相关文章
- Android动画效果之Property Animation进阶(属性动画)
前言: 前面初步认识了Android的Property Animation(属性动画)Android动画效果之初识Property Animation(属性动画)(三),并且利用属性动画简单了补间动画 ...
- Android动画效果之初识Property Animation(属性动画)
前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...
- Android属性动画
这几天看郭神的博客 Android属性动画完全解析(上),初识属性动画的基本用法之后,我自己突然想实现一种动画功能,就是我们在携程网.阿里旅行等等手机APP端买火车票的时候,看到有选择城市,那么就有出 ...
- Android动画:模拟开关按钮点击打开动画(属性动画之平移动画)
在Android里面,一些炫酷的动画确实是很吸引人的地方,让然看了就赏心悦目,一个好看的动画可能会提高用户对软件的使用率.另外说到动画,在Android里面支持3种动画: 逐帧动画(Frame Ani ...
- android 帧动画,补间动画,属性动画的简单总结
帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...
- View动画和属性动画
在应用中, 动画效果提升用户体验, 主要分为View动画和属性动画. View动画变换场景图片效果, 效果包括平移(translate), 缩放(scale), 旋转(rotate), 透明(alph ...
- Android属性动画源代码解析(超详细)
本文假定你已经对属性动画有了一定的了解,至少使用过属性动画.下面我们就从属性动画最简单的使用开始. ObjectAnimator .ofInt(target,propName,values[]) .s ...
- ObjectAnimator属性动画应用demo
感谢慕课网--eclipse_xu 布局文件:activity_main.xml <FrameLayout xmlns:android="http://schemas.android. ...
- 使用属性动画 — Property Animation
属性动画,就是通过控制对象中的属性值产生的动画.属性动画是目前最高级的2D动画系统. 在API Level 11中添加.Property Animation号称能控制一切对象的动画,包括可见的和不可见 ...
随机推荐
- python自动化运维笔记3 —— dns处理模块dnspython
1.3 DNS处理模块 dnspython是python实现的一个DNS工具包,它支持几乎所有的记录类型,可以用于查询.传输并动态更新ZONE信息,同时支持TSIG(事物签名)验证消息和EDNS0(扩 ...
- Performance testing test scenarios
1 check if page load time is within acceptable range2 check page load on slow connections 3 check re ...
- Linux系统——程序员跳槽必备
相信在看这篇文章的你,曾经或者现在是否跳槽呢,在北上广一线城市,你是否还在挣着那可怜巴巴的工资,过着拮据生活呢?但是自己想跳槽,却没有一技之长或者是自己的技术找工作太难了,那么我建议你学习下linux ...
- quartz 配置
<bean id="quartzJob" class="com.wistron.swpc.detaillog.common.SwfitFileAnalysis&qu ...
- BZOJ2595 WC2008游览计划(斯坦纳树)
斯坦纳树板子题. 考虑状压dp,设f[i][j][S]表示当前在点(i,j)考虑转移,其所在的联通块包含的关键点集(至少)为S的答案. 转移时首先枚举子集,有f[i][j][S]=min{f[i][j ...
- Leetcode 414.Fizz Buzz By Python
写一个程序,输出从 1 到 n 数字的字符串表示. 如果 n 是3的倍数,输出"Fizz": 如果 n 是5的倍数,输出"Buzz": 3.如果 n 同时是3和 ...
- Android ListView 列表视图
列表显示的三个元素 ListView : 用来显示列表的View Adapter : 适配器 用来把数据映射到ListView 上的中介 Data: 数据 将被映射的字符串,图片或者基本组件等资源 根 ...
- 青蛙跳台阶(C、Python)
C语言: /* ----------------------------------- 当n = 1, 只有1中跳法:当n = 2时,有两种跳法:当n = 3 时,有3种跳法:当n = 4时,有5种跳 ...
- SQL中on条件与where条件的区别
数据库在通过连接两张或多张表来返回记录时,都会生成一张中间的临时表,然后再将这张临时表返回给用户. 在使用left jion时,on和where条件的区别如下: 1.on条件是在生成临时表时使用 ...
- word公式的使用
插入->公式->插入新公式 优点:可以表示一些特殊符号,而且word公式的字更好看. 方法: 1.Shift+Enter,公式转入下一行 2.选择内嵌或显示 3.选择性粘贴->粘贴成 ...