Qt實現數字滾動動畫效果

2022-02-23 16:25:15 字數 2648 閱讀 4335

自己開發了一**票智慧型分析軟體,功能很強大,需要的點選下面的鏈結獲取:

如下圖所示,需要顯示人臉檢測的數量,變動畫的方式實現個位數字滾動,個位由9變成0時,十位也要滾動,實現進製。當個位十位都是9時,數字不在增加,而是顯示加號+。

實現方案,個位十位都有上下兩個label顯示數字。通過qpropertyanimation屬性動畫控制兩個label位置同時向上。動畫結束後,再將兩個label還原到原始位置。在還原位置之前,先前上面的labelnum值設定為下面labelnum1的值,下面labelnum1的值設定為+1後的值,避免出現數字閃現變小的問題。

標頭檔案實現

#ifndef numshowwidget_h

#define numshowwidget_h

#include

#include

#include

#include

#include"ui_numshowwidget.h"

#include

#include

#include

class numshowwidget : public qwidget

;#endif // numshowwidget_h

原始檔實現

#include "numshowwidget.h"

#include"hlog1.h"

#include

numshowwidget::numshowwidget()

);m_checktime.setinterval(1000);

connect(&m_checktime, &qtimer::timeout, this, &numshowwidget::slottimeaddnum);

m_checktime.start();

}numshowwidget::~numshowwidget()

}void numshowwidget::initnum()

void numshowwidget::setnum(int num, int time)

m_num = ui.labelten->text().toint()*10+ui.labelnum->text().toint();

if (num <= m_num)//值沒有變

addnum(num - m_num, time);

}void numshowwidget::addnum(int num, int time)

log_info("nucount lock");

int steptime = time / num;//動畫時間步長

tencurrent->setduration(steptime);

tendown->setduration(steptime);

m_count = num;

qparallelanimationgroup* paraanimation = new qparallelanimationgroup(this);

qpropertyanimation * gecurrent = new qpropertyanimation(m_gecurrent, "geometry");

gecurrent->setduration(steptime);

gecurrent->setstartvalue(qrect(15, 0, 12, 32));

gecurrent->setendvalue(qrect(15, -32, 12, 32));

paraanimation->addanimation(gecurrent);

qpropertyanimation *gedown = new qpropertyanimation(m_gedown, "geometry");

gedown->setduration(steptime);

gedown->setstartvalue(qrect(15, 32, 12, 32));

gedown->setendvalue(qrect(15, 0, 12, 32));

paraanimation->addanimation(gedown);

paraanimation->start();

connect(paraanimation, &qabstractanimation::finished, this, [=]()

else

m_gewei = 0;

}m_gedown->settext(qstring::number((m_gewei) % 10));

if (m_count > 0)

else})}

void numshowwidget::slottimeaddnum()}}

int numshowwidget::getnum()

else

}void numshowwidget::pushnum(int num)

qt設定開機啟動動畫 Qt實現程式啟動動畫

這次我們來演示乙個應用程式啟動時,新增啟動動畫的小例子。所謂啟動動畫,就是說當乙個應用程式啟動時,在展示主視窗之前,有可能會先去初始化一些執行環境,驗證使用者資訊等前提工作。那麼在這段空閒期程式的啟動過程是沒有使用者介面的,而使用者也無法得知程式的狀態,所以就需要在這段空白時間中,向使用者提供乙個展...

Qt實現程式啟動動畫

演示乙個應用程式啟動時,新增啟動動畫的小例子。所謂啟動動畫,就是說當乙個應用程式啟動時,在展示主視窗之前,有可能會先去初始化一些執行環境,驗證使用者資訊等前提工作。那麼在這段空閒期程式的啟動過程是沒有使用者介面的,而使用者也無法得知程式的狀態,所以就需要在這段空白時間中,向使用者提供乙個展示程式執行...

progress進度條滾動動畫

有兩個屬性 max 和 value。max 表示進度條的進度最大值,必須是大於0,預設值是1。value 表示當前完成的進度,值的範圍為0 max之間。如果沒有設定max屬性,那麼value屬性值的範圍要在0 1之間。預設的進度條的樣式為 修改進度條預設樣式的方法 1去除進度條的預設樣式 2prog...