我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

如何使用Qt自定义控件实现圆盘进度条-创新互联

这篇文章主要介绍如何使用Qt自定义控件实现圆盘进度条,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

在良庆等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供做网站、成都网站制作 网站设计制作按需定制,公司网站建设,企业网站建设,成都品牌网站建设,成都营销网站建设,外贸营销网站建设,良庆网站建设费用合理。

具体内容如下

自定义控件二:圆盘进度条

主要思路:使用qpainter根据图形需求 画圆和圆弧,画指针(多边形,指定坐标即可),根据具体的value值旋转坐标系,使指针达到旋转效果,旋转度数是根据value值,总共360度,占比求得。最中间需要画文字上去,每次更新value时调用update()方法,重绘界面。

主要代码:CMPassrate1.cpp

void CMPassrate1::paintEvent(QPaintEvent *event){  int width = this->width();  int height = this->height();  int side = qMin(width, height);  QPainter painter(this);  painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);  painter.translate(width / 2, height / 2);  painter.scale(side / 200.0, side / 200.0);  //绘制外圆  paintSide(&painter);  paintOutE(&painter);    paintLine(&painter);//绘制刻度线  paintInE(&painter);  paintPoint(&painter);//绘制指针  paintTextE(&painter);//绘制文字所在的圆  paintText(&painter);//绘制文字  paintValue(&painter);//绘制value对应的填充角度}void CMPassrate1::paintSide(QPainter *painter){  int radis = outRadis;  QRect rect(-radis,-radis,radis*2,radis*2);  painter->save();  painter->setBrush(QBrush(QColor("#505050")));  painter->setPen(Qt::NoPen);  painter->drawEllipse(rect);  painter->restore();}void CMPassrate1::paintOutE(QPainter *painter){  int radis = outRadis-side;  QRect rect(-radis,-radis,radis*2,radis*2);  painter->save();  painter->setBrush(QBrush(QColor("#868686")));  painter->setPen(Qt::NoPen);  painter->drawEllipse(rect);  painter->restore();}void CMPassrate1::paintLine(QPainter *painter){  int lineStart = outRadis-3;  painter->save();  painter->setPen(QColor("#868686"));  int range = 360/12;  for(int i = 0;i<12;i++){    painter->rotate(range);    painter->drawLine(QPoint(lineStart,0),QPoint(outRadis,0));  }  painter->restore();}void CMPassrate1::paintInE(QPainter *painter){  int radis = inRadis;  QRect rect(-radis,-radis,radis*2,radis*2);  painter->save();  painter->setBrush(QBrush(QColor("#646464")));  painter->setPen(Qt::NoPen);  painter->drawEllipse(rect);  painter->restore();}void CMPassrate1::paintTextE(QPainter *painter){  int radis = 23;  QRect rect(-radis,-radis,radis*2,radis*2);  painter->save();  painter->setBrush(QBrush(QColor("#FFFFFF")));  painter->setPen(Qt::NoPen);  painter->drawEllipse(rect);  painter->restore();}void CMPassrate1::paintPoint(QPainter *painter){   painter->save();   const QPoint points[3] = {       QPoint(10,0),       QPoint(-10,0),       QPoint(0,inRadis-5)     };   int range = ((double)value/100)*360;   painter->rotate(range);   painter->setPen(Qt::NoPen);   painter->setBrush(QBrush(QColor("#66CFFF")));   painter->drawConvexPolygon(points,3);   painter->restore();}void CMPassrate1::paintText(QPainter *painter){  int radis = 23;  QRect rect(-radis,-radis,radis*2,radis*2);  painter->save();  painter->setBrush(QBrush(QColor("#000000")));  painter->setPen(QPen(QColor("#000000")));  QFont font = painter->font();  font.setPixelSize(20);  painter->setFont(font);  painter->drawText(rect,Qt::AlignCenter,QString("%1%").arg(QString::number(value)));  painter->restore();}void CMPassrate1::paintValue(QPainter *painter){  int oRandis = outRadis-side;  qDebug()<<"value::"<save();  painter->setBrush(valueColor);  painter->setPen(Qt::NoPen);  painter->drawPath(path);  painter->restore();}

以上是“如何使用Qt自定义控件实现圆盘进度条”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


当前标题:如何使用Qt自定义控件实现圆盘进度条-创新互联
网址分享:http://shouzuofang.com/article/dhogcc.html

其他资讯