#include
#include
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QWidget w;
w.setFixedSize(550, 550);
QLabel *labelPic = new QLabel;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(labelPic);
w.setLayout(layout);
QPixmap p1("image/opengl-examples.png");
QPixmap p2("image/padnavigator-example.png");
QPixmap p3("image/paintsystem-painterpath.png");
QPixmap p4("image/paintsystem-svg.png");
p1 = p1.scaled(labelPic->size());
p2 = p2.scaled(labelPic->size());
p3 = p3.scaled(labelPic->size());
p4 = p4.scaled(labelPic->size());
QList listPic;
listPic << p2 << p1 << p3 << p4;
w.show();
int index = 0;
QPixmap mixPixmap(labelPic->size());
QPainter painter(&mixPixmap);
int iTransform = 3000; // ms
QElapsedTimer t2;
int iPos= 0;
QTime t1;
t1.start();
while(1)
{
if (t1.elapsed() > 2000)//because setPixmap clears any previous content
{
//move right to left
t2.start();
qint64 durationSecond = 0;
QSize size = mixPixmap.size();
iPos = 0;
while(t2.elapsed() < iTransform)
{
durationSecond = t2.elapsed();
iPos = durationSecond*size.width()/iTransform;
//
if (index%4 > 0)
painter.drawPixmap(mixPixmap.rect().adjusted(0,0,-iPos,0), listPic[index%4-1], mixPixmap.rect().adjusted(iPos,0,0,0));
//convert
painter.drawPixmap(mixPixmap.rect().adjusted(size.width()-iPos,0,0,0), listPic[index%4], mixPixmap.rect().adjusted(0,0,iPos-size.width(),0));
QApplication::processEvents();
labelPic->setPixmap(mixPixmap);
}
index++;
t1.restart();
}
else
QApplication::processEvents();
}
return app.exec();//no use
}