gpt4 book ai didi

c++ - Qt中如何多次显示一组动画?

转载 作者:行者123 更新时间:2023-11-30 05:47:14 25 4
gpt4 key购买 nike

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QMessageBox>
#include <QPushButton>


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

m_animation = new QPropertyAnimation(ui->label, "geometry");

startAnimation();
}

MainWindow::~MainWindow()
{
delete ui;
delete m_animation;
}

void MainWindow::startAnimation()
{
m_animation->setDuration(3000);

m_animation->setKeyValueAt(0, QRect(50, 50, 128, 128));
m_animation->setKeyValueAt(0.25, QRect(200, 50, 128, 128));
m_animation->setKeyValueAt(0.5, QRect(50, 50, 128, 128));
m_animation->setKeyValueAt(0.75, QRect(200, 50, 128, 128));
m_animation->setKeyValueAt(1, QRect(50, 50, 128, 128));

m_animation->start();
}

我想多次显示 startAnimation 函数中完成的动画,现在它只显示两次。我尝试使用 QSequential 但这也不起作用。我还尝试将此函数与线程连接,但是当我创建线程类的对象时,它显示未解析的符号错误。

最佳答案

您应该设置 loopCount属性(property)。

void MainWindow::startAnimation()
{
m_animation->setLoopCount(10);
m_animation->setDuration(3000);

m_animation->setKeyValueAt(0, QRect(50, 50, 128, 128));
m_animation->setKeyValueAt(0.25, QRect(200, 50, 128, 128));
m_animation->setKeyValueAt(0.5, QRect(50, 50, 128, 128));
m_animation->setKeyValueAt(0.75, QRect(200, 50, 128, 128));
m_animation->setKeyValueAt(1, QRect(50, 50, 128, 128));

m_animation->start();
}

关于c++ - Qt中如何多次显示一组动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28655846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com