一、效果预览图
二、代码构造思路
QPainter绘制背景图、QConicalGradient 构造颜色渐变对象、利用QPropertyAnimation创建动画
三、代码片段
#include "radarcycle.h"
RadarCycle::RadarCycle(QWidget *parent):
QWidget (parent)
{
resize(parent->size());
show();
init();
}
int RadarCycle::getRotate()
{
return m_rotation;
}
void RadarCycle::setRotate(int rotate)
{
m_rotation = rotate;
update();
}
void RadarCycle::init()
{
m_rotation = 0;
QPropertyAnimation *animation = new QPropertyAnimation(this, "rotate");
animation->setEasingCurve(QEasingCurve::Linear);
animation->setDuration(18000);
animation->setStartValue(0);
animation->setEndValue(360);
animation->setLoopCount(-1);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
void RadarCycle::paintEvent(QPaintEvent *event)
{
paintCycle(event,46,1);
paintCycle(event,46*2,1);
paintCycle(event,46*3,1);
paintCycle(event,46*4,1);
paintCycle(event,46*5,4);
paintTextScale(event);
paintLine(event);
paintPie(event);
}
void RadarCycle::paintCycle(QPaintEvent *event,int r,int w)
{
QRect rect = event->rect();
if