QT学习笔记-24.使用QTimeLine
2015-11-20 23:10
483 查看
一个简单的代码如下:
#include <QtGui/QApplication>
#ifndef TIMELINE_H
#define TIMELINE_H
#include <QtGui/QWidget>
#include <QVBoxLayout>
#include <QTimeLine>
#include <QProgressBar>
#include <QPushButton>
class timeline : public QWidget
{
Q_OBJECT
public:
timeline(QWidget *parent = 0);
~timeline();
private:
QPushButton *pushButton;
QTimeLine *timeLine;
QProgressBar *progressBar;
QVBoxLayout *layout;
};
#endif // TIMELINE_H
#include "timeline.h"
timeline::timeline(QWidget *parent):QWidget(parent)
{
layout= new QVBoxLayout(this);
progressBar = new QProgressBar(this);
progressBar->setRange(0, 100);
// Construct a 5-second timeline with a frame range of 0 - 100
timeLine = new QTimeLine(5000, this);
timeLine->setFrameRange(0, 100);
connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));
// Clicking the push button will start the progress bar animation
pushButton = new QPushButton(tr("Start animation"), this);
connect(pushButton, SIGNAL(clicked()), timeLine, SLOT(start()));
layout->addWidget(progressBar);
layout->addWidget(pushButton);
setLayout(layout);
}
timeline::~timeline()
{
// No need to delete any QObject that got proper parent pointer.
}
简单的说 QTimeLine就是一个带有线程的对象,通过设置持续时间和帧数来控制动画
FROM: http://www.cppblog.com/gaimor/archive/2011/09/07/155302.html
#include <QtGui/QApplication>
#include <QtGui>
#include <math.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsItem *ball = new QGraphicsEllipseItem(0,0,20,40);
QTimeLine *timer = new QTimeLine(15000);
timer->setFrameRange(0,100);
QGraphicsItemAnimation *animation = new QGraphicsItemAnimation;
animation->setItem(ball);
animation->setTimeLine(timer);
for(int i = 0; i < 600; ++i)
animation->setPosAt(i / 600.0, QPointF(i, i));
QGraphicsScene *scene = new QGraphicsScene();
scene->setBackgroundBrush(QBrush(Qt::blue));
scene->setSceneRect(0,0,250,250);
scene->addItem(ball);
QGraphicsView *view = new QGraphicsView(scene);
view->setBackgroundBrush(QBrush(Qt::red));
view->show();
timer->start();
return a.exec();
} 另外一个例子如下:
#ifndef TIMELINE_H
#define TIMELINE_H
#include <QtGui/QWidget>
#include <QVBoxLayout>
#include <QTimeLine>
#include <QProgressBar>
#include <QPushButton>
class timeline : public QWidget
{
Q_OBJECT
public:
timeline(QWidget *parent = 0);
~timeline();
private:
QPushButton *pushButton;
QTimeLine *timeLine;
QProgressBar *progressBar;
QVBoxLayout *layout;
};
#endif // TIMELINE_H
#include "timeline.h"
timeline::timeline(QWidget *parent):QWidget(parent)
{
layout= new QVBoxLayout(this);
progressBar = new QProgressBar(this);
progressBar->setRange(0, 100);
// Construct a 5-second timeline with a frame range of 0 - 100
timeLine = new QTimeLine(5000, this);
timeLine->setFrameRange(0, 100);
connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int)));
// Clicking the push button will start the progress bar animation
pushButton = new QPushButton(tr("Start animation"), this);
connect(pushButton, SIGNAL(clicked()), timeLine, SLOT(start()));
layout->addWidget(progressBar);
layout->addWidget(pushButton);
setLayout(layout);
}
timeline::~timeline()
{
// No need to delete any QObject that got proper parent pointer.
}
简单的说 QTimeLine就是一个带有线程的对象,通过设置持续时间和帧数来控制动画
FROM: http://www.cppblog.com/gaimor/archive/2011/09/07/155302.html
相关文章推荐
- 深入浅出理解QTimeLine类
- OpenCV2.x自学笔记——Qt5.5.1打包exe
- VS集成Qt环境搭建
- QT-1-环境搭建QT5.4.1&MinGW4.9.1
- QT5.5移植到ARM全攻略
- QT5.5移植全攻略
- Qt QRegExpValidator内置检验器
- Qt 自动建立信号-槽关系
- Qt:让任意线程执行一个匿名函数
- QT的文件对话框
- Qt 深入介绍信号和槽
- Qt 创建对话框
- QT中的各种MessageBox
- QT程序图标和窗口图标
- QT.Debug设置断点无效
- qt QSharedMemory 用法
- qt 打印信息显示行号
- Qt moc 功能和限制
- Qt之右键菜单实现
- QT创建透明窗体