属性动画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号称能控制一切对象的动画,包括可见的和不可见 ...
随机推荐
- 二本毕业,我是如何逆袭成为BAT年薪40W的Java工程师的?
身边的师弟师妹经常问到:非计算机专业出身,你是在2年内如何逆袭成BAT年薪40W的资深开发工程师的.其实很简单——努力! 我16年毕业于普通的二本学校,非计算机专业出身,只因为对软件开发感兴趣,所以找 ...
- 普通javabean 获得项目的绝对路径
方式一:String path = RequestContext.class.getResource("/").getFile();
- python构建bp神经网络_曲线拟合(一个隐藏层)__1.可视化数据
1.将数据写入csv文件,应该可以python代码直接实现数据集的写入,但我对文件读取这块不太熟练,等我成功了再加上,这里我直接手写将数据集写入Excel 2.然后把后缀改成.csv就可以了,利用pa ...
- 架构师成长之路6.1 DNS理论
点击返回架构师成长之路 架构师成长之路6.1 DNS理论 1.DNS一些基本概念 ① FQDN:Full Qualified Domain Name,完全限定域名,即每个域在全球网络都是唯 ...
- [BZOJ5248] 2018九省联考 D1T1 一双木棋 | 博弈论 状压DP
题面 菲菲和牛牛在一块\(n\)行\(m\)列的棋盘上下棋,菲菲执黑棋先手,牛牛执白棋后手. 棋局开始时,棋盘上没有任何棋子,两人轮流在格子上落子,直到填满棋盘时结束. 落子的规则是:一个格子可以落子 ...
- 洛谷 P1582 倒水 解题报告
P1582 倒水 题目描述 一天,CC买了N个容量可以认为是无限大的瓶子,开始时每个瓶子里有1升水.接着~~CC发现瓶子实在太多了,于是他决定保留不超过K个瓶子.每次他选择两个当前含水量相同的瓶子,把 ...
- tf 常用函数 28原则
一个tensorflow图由以下几部分组成: 占位符变量(Placeholder)用来改变图的输入. 模型变量(Model)将会被优化,使得模型表现得更好. 模型本质上就是一些数学函数,它根据Plac ...
- 修复VirtualBox "This kernel requires the following features not present on the CPU: pae Unable to boot – please use a kernel appropriate for your CPU"
异常处理汇总-开发工具 http://www.cnblogs.com/dunitian/p/4522988.html 修复VirtualBox "This kernel requires ...
- 手动实现staticmethod和classmethod装饰器
首先,staticmethod和classmethod装饰器是通过非数据描述符实现的.用法简单,这里就不细说了. 这里主要分析一下staticmethod和classmethod是如何通过描述符实现的 ...
- ECMAScript 6 -- 数组的解构赋值
模式匹配:只要等号两边的模式相同,左边的变量就会被赋予对应的值. let [a, b, c] = [1, 2, 3]; 嵌套数组进行解构: let [foo, [[bar], baz]] = [1, ...