qt 在label上以光标位置进行缩放_缩放|位移|渐变简单动画
生活随笔
收集整理的這篇文章主要介紹了
qt 在label上以光标位置进行缩放_缩放|位移|渐变简单动画
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
本文簡單介紹Qt的一些動畫效果(縮放,位移,漸變)。
縮放動畫
將窗口的geometry(位置,大小)屬性作為動畫參考實現(xiàn)縮放動畫。
代碼
w->setWindowTitle(QStringLiteral("縮放動畫@Qt君"));
w->resize(320,?240);
QLabel?*label?=?new?QLabel(w);
/*?創(chuàng)建一個動畫對象?*/
QPropertyAnimation?*animation?=?new?QPropertyAnimation(label);
/*?設(shè)置動畫持續(xù)時長?*/
animation->setDuration(3000);
/*?設(shè)置動畫目標(biāo)?*/
animation->setTargetObject(label);
/*?設(shè)置窗口幾何屬性(位置,大小)作為動畫參考?*/
animation->setPropertyName("geometry");
/*?設(shè)置動畫開始坐標(biāo)和大小(QRect)?*/
/*?居中顯示數(shù)值計算:160?=>?(320/2 - 100); 120?=>?(240/2 - 100)?*/
animation->setStartValue(QRect(160,?120,?0,?0));
/*?設(shè)置動畫結(jié)束坐標(biāo)和大小(QRect)?*/
/*?居中顯示數(shù)值計算(差值是基于開始動畫的100/2):160?=>?(160?- 100/2); 70?=>?(120?- 100/2)?*/
animation->setEndValue(QRect(110,?70,?100,?100));
/*?設(shè)置循環(huán)次數(shù):-1為無限次?*/
animation->setLoopCount(-1);
/*?開始動畫?*/
animation->start();
w->show();
位移動畫
將窗口的pos位置作為動畫參考實現(xiàn)位移動畫。
代碼
w->setWindowTitle(QStringLiteral("位移動畫@Qt君"));
w->resize(320,?240);
QLabel?*label?=?new?QLabel(w);
label->resize(100,?100);
/*?創(chuàng)建一個動畫對象?*/
QPropertyAnimation?*animation?=?new?QPropertyAnimation(label);
/*?設(shè)置動畫目標(biāo)?*/
animation->setTargetObject(label);
/*?設(shè)置窗口的位置作為動畫參考?*/
animation->setPropertyName("pos");
/*?設(shè)置動畫持續(xù)時長?*/
animation->setDuration(3000);
/*?設(shè)置動畫開始位置?*/
animation->setStartValue(QPoint(0,?70));
/*?設(shè)置動畫結(jié)束位置?*/
animation->setEndValue(QPoint(220,?70));
/*?設(shè)置循環(huán)次數(shù):-1為無限次?*/
animation->setLoopCount(-1);
/*?開始動畫?*/
animation->start();
w->show();
漸變動畫
使用QGraphicsOpacityEffect配合QPropertyAnimation實現(xiàn)漸變動畫。
代碼
w->setWindowTitle(QStringLiteral("漸變動畫@Qt君"));
w->resize(320,?240);
/*?創(chuàng)建一個不透明效果對象?*/
QGraphicsOpacityEffect?*opacityEffect?=?new?QGraphicsOpacityEffect;
opacityEffect->setOpacity(1);
QLabel?*label?=?new?QLabel(w);
label->setGeometry(110,?70,?100,?100);
/*?設(shè)置控件的圖形效果?*/
label->setGraphicsEffect(opacityEffect);
/*?創(chuàng)建一個動畫對象?*/
QPropertyAnimation?*animation=?new?QPropertyAnimation(label);
/*?設(shè)置動畫目標(biāo)?*/
animation->setTargetObject(opacityEffect);
/*?設(shè)置窗口的不透明度作為動畫參考?*/
animation->setPropertyName("opacity");
/*?設(shè)置動畫持續(xù)時長?*/
animation->setDuration(3000);
/*?設(shè)置動畫開始的不透明度?*/
animation->setStartValue(0);
/*?設(shè)置動畫結(jié)束的不透明度?*/
animation->setEndValue(1);
/*?設(shè)置循環(huán)次數(shù):-1為無限次?*/
animation->setLoopCount(-1);
/*?開始動畫?*/
animation->start();
w->show();
動畫的幾點要素
關(guān)于更多
- 本文源碼例子在公眾號聊天界面回復(fù)"入群"后在群文件獲取。
總結(jié)
以上是生活随笔為你收集整理的qt 在label上以光标位置进行缩放_缩放|位移|渐变简单动画的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java两个长度不同数组_两组数组,长度
- 下一篇: php数组能不能静态,php 为什么常量