Qt:QSequentialAnimationGroup

1059 篇文章 286 订阅
#include "widget.h"
#include <QPushButton>
#include <QPropertyAnimation>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(300, 200);

    QPushButton *btn1 = new QPushButton("first", this);
    btn1->setGeometry(10, 10, 100, 30);

    QPushButton *btn2 = new QPushButton("second", this);
    btn2->setGeometry(10, 45, 100, 30);

    QPropertyAnimation *anim1 = new QPropertyAnimation(btn1, "geometry");
    anim1->setDuration(2000);
    anim1->setStartValue(QRectF(10, 10, 100, 30));
    anim1->setEndValue(QRectF(200, 150, 100, 30));

    QPropertyAnimation *anim2 = new QPropertyAnimation(btn2, "geometry");
    anim2->setDuration(2000);
    anim2->setStartValue(QRect(10, 45, 100, 30));
    anim2->setEndValue(QRect(200, 195, 100, 30));

//    sGroup = new QSequentialAnimationGroup; // Sequential Group
//    sGroup->addAnimation(anim1);
//    sGroup->addAnimation(anim2);

    pGroup = new QParallelAnimationGroup; // Parallel Group
    pGroup->addAnimation(anim1);
    pGroup->addAnimation(anim2);

    connect(btn1, SIGNAL(clicked()), this, SLOT(btn_clicked()));
    connect(btn2, SIGNAL(clicked()), this, SLOT(btn_clicked()));
}

void Widget::btn_clicked()
{
   // sGroup->start(QPropertyAnimation::DeleteWhenStopped);  //如果动画完成自动清理内存
    //因此移动一次之后就算再次点击按钮也不会移动了
    pGroup->start(QPropertyAnimation::DeleteWhenStopped);
}

c9da6d9ff7c89a9f2527a6675bbab79653f.jpg

b84fa883d10e00e73b29079adcc498bcef5.jpg

任意一个按钮点击都都会移动按钮,先移动按钮1,再移动按钮2

ee771c7e079bc4054f52441c011c59868fc.jpg

c580a0029b629c0c8e3546fe307648a3809.jpg

任意一个按钮点击都都会移动按钮:按钮1&按钮2并行移动

 

串行顺序运行动画对象

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint)` 是一个 Qt 函数调用,用于将窗口设置为工具提示窗口,并且始终保持在顶部,并且窗口没有边框。这个函数可以在创建窗口时调用,也可以在运行时调用。 下面是一个使用 `setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint)` 的例子。在这个例子中,我们创建了一个简单的窗口,并将其设置为工具提示窗口、始终在顶部,并且没有边框: ```cpp #include <QtWidgets> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.setGeometry(100, 100, 200, 200); window.setWindowTitle("Tool Window"); window.show(); // Set the window to be a tool window, always on top, and frameless window.setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint); return app.exec(); } ``` 在上面的例子中,我们创建了一个名为 `window` 的 `QWidget` 对象,并通过 `setGeometry` 函数设置了窗口的位置和大小。随后,我们将窗口的标题设置为 `"Tool Window"`,并将其显示出来。最后,我们调用 `setWindowFlags` 函数,并将其参数设置为 `Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint`,以将窗口设置为工具提示窗口、始终在顶部,并且没有边框。 需要注意的是,如果您想取消窗口的 `Tool`、`WindowStaysOnTopHint`、`FramelessWindowHint` 标志位,可以使用 `clearMask(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint)` 函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值