• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Qt自定义控件实现线条型加载条

qt 搞代码 4年前 (2022-01-06) 20次浏览 已收录 0个评论

这篇文章主要为大家详细介绍了Qt自定义控件实现线条型加载条,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Qt自定义控件实现线条型加载条的具体代码,供大家参考,具体内容如下

上效果图:

思路:先画一个线条,然后旋转坐标系再画其他线条,突出颜色的线条可以画死再旋转,也可以按照角度递增让特定线画突出颜色(这里使用的是这种)。

 LoadingBarA::LoadingBarA(QWidget *parent) : QWidget(parent) { timer = new QTimer(this); //定时器 timer->setInterval(50); connect(timer,QTimer::timeout,this,[=](){ if(pointRectwidth(); 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); float degree = 360.0/rectCount; //rectCount:共有多少根线条 for(int i =0;isave(); painter->setPen(Qt::NoPen); painter->setBrush(color); QRect rect(arcLength,-rectHeight/2,rectWidth,rectHeight); painter->drawRoundedRect(rect,rectHeight/2,rectHeight/2); painter->restore(); } void LoadingBarA::setDarkColor(QColor tempColor){ this->darkColor = tempColor; update(); } void LoadingBarA::setLightColor(QColor lightColor){ this->lightColor = lightColor; update(); } void LoadingBarA::setRectWidth(int l){ this->rectWidth = l; update(); } void LoadingBarA::setRectHeight(int l){ this->rectHeight = l; update(); } void LoadingBarA::setArcLength(int l){ this->arcLength = l; update(); } void LoadingBarA::setRectCount(int l){ this->rectCount = l; update(); } void LoadingBarA::startLoading(){ //设置开始 timer->start(<strong style="color:transparent">来源gaodaima#com搞(代@码网</strong>); }

以上就是Qt自定义控件实现线条型加载条的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Qt自定义控件实现线条型加载条
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址