【Qt】应用程序列表转起来 in QT4.6

应用程序列表转起来

✿我的需求

拒绝应用程序列表的1234陈列图标状,实现360°转动效果。

PS:录制效果很卡,帧效果很差,实际效果很流畅,请发挥最完美的想象-_-||

✿我的实现方案

我用QPropertyAnimation实现Button的转动效果。思路就是,在一个周期时间里,对应改变Button的坐标位置。

为了让效果看起来更平滑,更自然,建议多定义几个状态 0,0.3,0.5 ,0.7, 1为宜,根据屏幕大小具体分析。

QPropertyAnimation *animation = new QPropertyAnimation(button, "geometry");

animation->setDuration(clk);

animation->setKeyValueAt(0,QRect(x1, y1, w1, h1));

animation->setKeyValueAt(0.5,QRect((x1+x2)/2, (y1+y2)/2+20, ((w1+w2)*2)/3, (h1+h2)/2));

animation->setKeyValueAt(1,QRect(x2, y2, w2, h2));

在改变位置的同时,需要让按钮上的图标图片也随着自然改变大小。

QPropertyAnimation *animationlefticon = new QPropertyAnimation(button,"iconSize");

animationlefticon->setDuration(clk);

animationlefticon->setKeyValueAt(0,QSize(w1,h1));

animationlefticon->setKeyValueAt(0.5,QSize((w1+w2)/2,(h1+h2)/2));

animationlefticon->setKeyValueAt(1,QSize(w2,h2));

这样仅仅是一帧的操作,即位置改变一次。(以第一个button为例,反复的从左边的位置移到中间的位置)

怎么样实现状态的连续改变,怎么样记录每个按钮当前的位置的信息值?

当应用程序列表中的程序个数大于3个,如何实现交替轮换其中的3个显示?

———— 答案 是:用一个array[]来更新当前帧的位置信息

//用apparray记录应用程序列表,用int f 来标记当前帧所指向的app

apparray[0] = button1;

apparray[1] = button2;

apparray[2] = button3;

......

apparray[n-1] = buttonn;

f = 1;

//每次改变状态后,刷新当前位置

f++;

if(f<0) f=n-1;

if(f>n-1) f=0;

void update()

{

if((f-1)<0 ) left = apparray[2];

else left = apparray[f-1];

if((f+1)>n-1) right = apparray[0];

else right = apparray[f+1];

}

✿写在最后

欢迎交流,欢迎转载,但是希望你尊重我,注明出处,谢谢。

——茜。

你可能感兴趣的:(应用程序)