Skip to main content
 首页 » 编程设计

python之是否可以以某种方式在没有计时器的情况下为多个 Qt 效果设置动画

2025年05月04日15jackei

我想制作带有内置 Qt 效果的动画,例如文本同时消失和模糊,但不幸的是,可以只为一个对象分配一种效果..然后你必须通过你的手和计时器来完成这一切..我想知道有没有办法制作几种效果的动画一个小部件?

举个例子:

from PyQt4 import QtGui, QtCore 
import sys 
 
app = QtGui.QApplication(sys.argv) 
 
win = QtGui.QMainWindow() 
lbl = QtGui.QLabel() 
win.setCentralWidget(lbl) 
 
lbl.setFont(QtGui.QFont('Arial', 100)) 
lbl.setText('Hello, World!') 
 
win.show() 
 
effect1 = QtGui.QGraphicsOpacityEffect() 
effect2 = QtGui.QGraphicsBlurEffect()  # <- how to attach this one also? 
lbl.setGraphicsEffect(effect1) 
 
anim = QtCore.QPropertyAnimation(effect1, 'opacity') 
anim.setDuration(1000) 
anim.setStartValue(1) 
anim.setEndValue(0) 
anim.start() 
 
sys.exit(app.exec_()) 

提前致谢!

请您参考如下方法:

I'd like to make the animation with built-in Qt effects, e.g. simultaneous disappearing and blurring of text, but unfortunatelly it is possible to assign only one effect to an object.. and then you have to make it all by your hands and timers.. I wonder is there any way to make animation of several effects with one widget?

现代技术将是 QML:Usecase - Animations In QML .有多个 blur效果可用。使用 QML,我们对 QML 对象状态之间的转换进行编程:在我们的例子中,不太模糊和更模糊,或者反之亦然。至于用 Python 做 QML,我不确定,但即使没有 C++,你也可以只用声明性的 QML 和 JavaScript 创建应用程序。似乎即使使用 Python 也有一些技术可以使其与 QML 一起使用 available .