谢邀,刚好在写文章,顺便帮你写了个Qt版本的例子,你可以将C++代码改成python的
头文件:
#ifndef CLOSEWIDGET_H
#define CLOSEWIDGET_H
#include
class QPropertyAnimation;
class CloseWidget : public QWidget
{
Q_OBJECT
public:
CloseWidget(QWidget *parent = 0);
protected:
void closeEvent(QCloseEvent* e);
private:
QPropertyAnimation *animation;
};
#endif // CLOSEWIDGET_H
源文件:
#include
#include
#include "closewidget.h"
CloseWidget::CloseWidget(QWidget *parent)
: QWidget(parent)
{
animation = NULL;
}
void CloseWidget::closeEvent(QCloseEvent *e)
{
if (!animation)
{
animation = new QPropertyAnimation(this, "windowOpacity");
animation->setDuration(1000);
animation->setStartValue(1);
animation->setEndValue(0);
connect(animation, SIGNAL(finished()), this, SLOT(close()));
animation->start();
e->ignore();
}
}
整体思路:
1 重新closeEvent事件,在里面截取关闭事件,使用ignore,禁止向父对象传递事件。
2 创建一个属性动画,属性选择透明度。
3 动画结束后,关闭窗口。
欢迎关注我的专栏跟小豆君学Qt
微信公众号:小豆君,只要关注,便可加入小豆君为大家创建的C++\Qt交流群,方便讨论学习。