QT之窗口动画效果展示

窗口的透明淡化一直隐藏的效果:

	QPropertyAnimation *pAnimation = new QPropertyAnimation(_guiTest, "windowOpacity");
	pAnimation->setDuration(1000);
	pAnimation->setKeyValueAt(0, 1);
	pAnimation->setKeyValueAt(0.5, 0);
	pAnimation->setKeyValueAt(1, 1);
	pAnimation->start(QAbstractAnimation::DeleteWhenStopped);

窗口最小化:

	QPropertyAnimation *pAnimation = new QPropertyAnimation(_guiTest, "geometry");

	QRect startRect = rect();
	startRect.moveTo(pos());
	QRect stopRect = QRect(startRect.center(), QSize(0, 0));

	pAnimation->setStartValue(startRect);
	pAnimation->setEndValue(stopRect);
	pAnimation->start(QAbstractAnimation::DeleteWhenStopped);

窗口飞走:

QPropertyAnimation *pAnimation = new QPropertyAnimation(_guiTest, "pos");

	QDesktopWidget *pDesktopWidget = QApplication::desktop();
	int x = (pDesktopWidget->availableGeometry().width() - width()) / 2;
	int y = (pDesktopWidget->availableGeometry().height() - height()) / 2;
	pAnimation->setDuration(2000);
	pAnimation->setStartValue(QPoint(x,y));
	pAnimation->setEndValue(QPoint(x - width(), y));
	//pAnimation->setStartValue(QRect(x, 0, width(), height()));
	//pAnimation->setEndValue(QRect(x, y, width(), height()));
	//pAnimation->setEasingCurve(QEasingCurve::OutElastic);
	pAnimation->start(QAbstractAnimation::DeleteWhenStopped);

aaa

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Python Qt中可以使用QPropertyAnimation类来实现动画效果。下面是一个简单的例子: ```python from PyQt5.QtCore import Qt, QPropertyAnimation from PyQt5.QtGui import QPainter, QColor, QPen from PyQt5.QtWidgets import QApplication, QWidget class MyWidget(QWidget): def __init__(self): super().__init__() self.setGeometry(100, 100, 400, 300) self.color = QColor(255, 0, 0) self.pen = QPen(self.color, 5, Qt.SolidLine) self.animation = QPropertyAnimation(self, b"color") self.animation.setDuration(1000) self.animation.setStartValue(QColor(255, 0, 0)) self.animation.setEndValue(QColor(0, 0, 255)) self.animation.setLoopCount(-1) self.animation.start() def paintEvent(self, event): painter = QPainter(self) painter.setPen(self.pen) painter.drawLine(0, 0, self.width(), self.height()) painter.drawLine(self.width(), 0, 0, self.height()) def getColor(self): return self.color def setColor(self, color): self.color = color self.pen.setColor(color) self.update() color = property(getColor, setColor) if __name__ == '__main__': app = QApplication([]) widget = MyWidget() widget.show() app.exec_() ``` 在这个例子中,我们创建了一个MyWidget类,继承自QWidget类,重写了paintEvent方法,在paintEvent方法中使用QPainter类绘制了两条对角线。 我们使用QPropertyAnimation类来实现颜色的变化。在MyWidget类的构造函数中,我们初始化了color属性和pen属性,并创建了一个QPropertyAnimation对象。在QPropertyAnimation对象中,我们设置了动画的起始值、结束值和持续时间,并使用setLoopCount方法使动画无限循环。最后,我们调用start方法来启动动画。 我们还定义了getColor方法和setColor方法来获取和设置color属性。在setColor方法中,我们设置了pen的颜色,并调用update方法来重绘窗口。 当程序运行时,我们会看到两条对角线不断变化颜色。这就是使用QPropertyAnimation类实现动画效果的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wb175208

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值