php幻灯片切换,QT怎么实现幻灯片的切换效果

#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

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值