Qt环境下使用动画效果动态显示日期时间:
1,大部分的实现方式是使用ui设计,直接加载datetime的label;(关于这部分,帖子很多,不在详细描述)。
2,在开发过程中没有使用到.ui设计,所以想将datetime的label动态显示,测试后,通过GraphicsView里的QGraphicsProxyWidget进行实现,将Qlabel中的datetime,定时器每隔1s刷新一次。
代码实现:
主体类继承GraphicsView,并通过GraphicsView.setScene()显示。
(注,以下代码只摘抄主要实现部分,其余自行补充实现)
#include <QGraphicsScene>
#include <QLabel>
#include <QObject>
QGraphicsProxyWidget *TimeWidget_;
QGraphicsProxyWidget *DateWidget_;
QLabel *TimeLabel_;
QLabel *DateLabel_;
QTimer *dtTimer_ = new QTimer();
connect(dtTimer_, SIGNAL(timeout()), this, SLOT(OndtTime()));
dtTimer_->setTimerType(Qt::PreciseTimer);
dtTimer_->setInterval(1000);
dtTimer_->start();
void OndtTime()
{
if(TimeLabel_)
{
SAFE_RELEASE(TimeLabel_);
TimeWidget_ = NULL;
}
if(DateLabel_)
{
SAFE_RELEASE(DateLabel_);
DateWidget_ = NULL;
}
QString format_ =