资源介绍
qt 时间线 对初学者很有帮助
/***************************************************************************
* Copyright (C) 2009 by shiroki@www.cuteqt.com*
* shiroki@cuteqt.com *
* *
***************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include "mainwin.h"
#define QUANTITY 20
MainWin::MainWin(QWidget*p, Qt::WFlags f)
:QWidget(p), pixmap("./background.png")
{
setFixedSize(800,600);
QTimeLine* tl = new QTimeLine(2000, this);//total time
connect(tl, SIGNAL(frameChanged(int)), this, SLOT(changePixmap(int)));
tl->setFrameRange(0,100);//max value
tl->setCurveShape(QTimeLine::LinearCurve);
tl->setUpdateInterval(100);//step
tl->start();
}
void MainWin::paintEvent(QPaintEvent*e)
{
QPainter painter(this);
painter.setClipRect(e->rect());
painter.drawPixmap(e->rect(),pixmap, e->rect());
}
void MainWin::changePixmap(int value)
{
static int oldx = 0;
qWarning() << "change pixmap..." << value;
QPainter p(&pixmap);//change pixmap
int width = pixmap.width();
if( width > rect().width())
width = rect().width();
int height = pixmap.height();
if( height > rect().height())
height = rect().height();
int x = width * value / 100;
QRect updaterect(oldx, 0, x-oldx + 1, height);
qWarning() << value << x << oldx ;
p.fillRect(updaterect, QColor(Qt::black));
//p.fillRect(updaterect, palette().color(QPalette::Base));
repaint(updaterect);
oldx = x;
}
- 上一篇: 基于QT绘制可交互的Bezier曲线(仅供学习)
- 下一篇: 时间轴,事件时间轴完整代码