QObject控件运动框架

Qt provides an easy way to animate Widgets or any other objects that inherit the QObject class through its powerful animation framework.

继承于QObject的控件或者类可以方便用Qt运动框架来实现动态动作。

The animation can be used either on its own or together with the  state machine framework, which allows different animations to be played based on

the current active state of the widgets.

控件运动动作可以用在单独控件上或者结合状态机来实现多个不同的运动动作。

Qt's animation framework also supports grouped animation, which allows you to move more than one graphics item simultaneously or

move them in sequence, one after the other.

Qt的动作框架还可以做成动作组,从而实现可视化动作的连续性或者队列化。

动作框架头文件为

#include <QPropertyAnimation>

测试代码

QPropertyAnimation *animation = new QPropertyAnimation(ui->pushButton, "geometry");
animation->setDuration(10000);
animation->setStartValue(ui->pushButton->geometry());
animation->setEndValue(QRect(200, 200, 100, 50));
animation->start();

把这个代码放入到按钮事件中:

void MainWindow::keyPressEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_M)
    {
        QPropertyAnimation *animation = new QPropertyAnimation(ui->lineEdit, "geometry");
        animation->setDuration(10000); //动作时间
        animation->setStartValue(ui->lineEdit->geometry()); //开始动作值
        animation->setEndValue(QRect(200, 200, 100, 50)); //结束动作值
        animation->start(); //开始动作
        //this->close();
    }

    qDebug() << event->text() << "has been pressed";
}

效果如下:

多谢,亲爱的美美。

猜你喜欢

转载自blog.csdn.net/islinyoubiao/article/details/113750611