Qt之动画编程之窗体透明度效果

Qt之动画编程之窗体透明度效果_第1张图片

#ifndef OPACITY_WIDGET_H
#define OPACITY_WIDGET_H
#include
#include
class opacity_widget:public QWidget
{

    Q_OBJECT
    Q_PROPERTY(qreal opacity READ windowOpacity WRITE setWindowOpacity)
public:
    opacity_widget(QWidget *parent=nullptr);

private:
    QPropertyAnimation *_animation;
};

#endif // OPACITY_WIDGET_H

#include "opacity_widget.h"

opacity_widget::opacity_widget(QWidget *parent):QWidget(parent)
{

    resize(400,300);
    _animation = new QPropertyAnimation(this, "opacity", this);
    _animation->setDuration(2000);


    _animation->setStartValue(1.0);
    _animation->setEndValue(0.2);
    _animation->start();

}

你可能感兴趣的:(Qt实战,qt,android,开发语言)