Qt开发之路——界面切换特效

参考了大佬写的文章
https://blog.csdn.net/hezf_hero/article/details/50187483

话不多说,直接上代码,说原理
addid.cpp
这是一个名为addid的ui界面,大佬使用了一个label来获取整个界面的的大小和图像,然后使用QPropertyAnimation 绑定,使用setDuration设置动画时长为1000ms,使用setStartValue和setEndValue来固定一个矩阵的位置,大佬巧妙的使用了QRect,QRect的方法前两个参数是界面初始的位置,后两个参数就是界面的实际宽和高。也就是说通过在固定矩阵内改变将纵坐标的位置从-height改为height,即实现了上滑特效。
代码:

AddId::AddId(Widget *parent)
    :Widget(parent)
    ,ui(new Ui::AddId)
{
    ui->setupUi(this);

    //界面出现特效——上滑
    QLabel *label = new QLabel(this);
    label->resize(this->size());
    label->setPixmap(this->grab());
    label->show();
    QPropertyAnimation *animation= new QPropertyAnimation(label,"geometry");
    animation->setDuration(1000);
    animation->setStartValue(this->geometry());
    animation->setEndValue(QRect(0, -this->height(), this->width(), this->height()));
    animation->start();
}

你可能感兴趣的:(#,Qt,Basic,qt,界面切换特效)