qt-動畫圓圈等待-LED數字

qt-動畫圓圈等待-LED數字

  • 一、演示效果
  • 二、關鍵程序
  • 三、下載鏈接

一、演示效果

在這里插入圖片描述

二、關鍵程序

#include "LedNumber.h"
#include <QLabel>LEDNumber::LEDNumber(QWidget *parent) : QWidget(parent)
{//設置默認寬高比setScale((float)0.6);//設置默認背景色setBackColor(QColor(85,85,85));//設置默認文字顏色setFrontColor(QColor(255,255,255));//設置中間線顏色setLineColor(QColor(60,60,60));//設置默認文字setText("2");//設置默認文字大小setFontSize(40);//設置默認最小尺寸this->setMinimumSize(100,100);
}//**********************************************  設置部分 ****************************************
//設置文字顏色
void LEDNumber::setFrontColor(const QColor & color)
{_frontColor=color;
}//設置背景色
void LEDNumber::setBackColor(const QColor & color)
{_backColor=color;
}//設置中間線顏色
void LEDNumber::setLineColor(const QColor& color)
{_lineColor=color;
}//設置寬高比
void LEDNumber::setScale(float scale)
{_scale=scale;
}//設置文字
void LEDNumber::setText(QString text)
{_text=text;
}void LEDNumber::setFontSize(int size)
{_fontSize=size;
}//**********************************************  繪制部分 ****************************************
void LEDNumber::resizeEvent(QResizeEvent *event)
{//計算繪制區域caculateArea();
}void LEDNumber::paintEvent(QPaintEvent *event)
{Q_UNUSED(event)QPainter painter(this);painter.setRenderHint(QPainter::Antialiasing);//計算繪制區域
//    caculateArea();//繪制背景drawBack(painter);//繪制文字drawText(painter);//繪制中間線drawLine(painter);
}//計算繪制區域
void LEDNumber::caculateArea()
{if((this->height()-2)*_scale>(this->width()-2)){_width=this->width()-2;_height=_width/_scale;}else{_height=this->height()-2;_width=_height*_scale;}
}//繪制背景
void LEDNumber::drawBack(QPainter & painter)
{QPen pen(_backColor,1);painter.setPen(pen);QPainterPath path;path.addRoundedRect(1,1,_width,_height,10,10);painter.fillPath(path,_backColor);painter.drawPath(path);
}//繪制文字
void LEDNumber::drawText(QPainter& painter)
{QPen pen(_frontColor);painter.setPen(pen);painter.setFont(QFont("Microsoft YaHei",_fontSize,75));painter.drawText(0,0,_width,_height,Qt::AlignCenter,_text);
}//繪制中間線
void LEDNumber::drawLine(QPainter & painter)
{QPen pen(_lineColor,3);painter.setPen(pen);painter.drawLine(1,_height/2,_width+1,_height/2);
}
#include "Loading.h"
#include "qmath.h"
#include <QDebug>Loading::Loading(QWidget *parent) : QWidget(parent),_i(0),_interval(50),_index(0)
{//設置背景透明//this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);//this->setAttribute(Qt::WA_TranslucentBackground, true);setDotColor(QColor(49, 177, 190));setDotCount(20);connect(&timer,&QTimer::timeout,this,&Loading::refresh);setMaxDiameter(30);setMinDiameter(5);
}//********************************************** 設置部分 *************************************
//設置點的個數
void Loading::setDotCount(int count)
{_count=count;
}//設置點的顏色
void Loading::setDotColor(const QColor & color)
{_dotColor=color;
}//開始動畫
void Loading::start()
{timer.setInterval(_interval);timer.start();
}//設置最大直徑
void Loading::setMaxDiameter(float max)
{_maxDiameter=max;
}//設置最小直徑
void Loading::setMinDiameter(float min)
{_minDiameter=min;
}
//********************************************** 繪制部分 *************************************
//刷新界面
void Loading::refresh()
{repaint();
}void Loading::resizeEvent(QResizeEvent *event)
{Q_UNUSED(event)caculate();
}void Loading::paintEvent(QPaintEvent *event)
{Q_UNUSED(event)QPainter painter(this);painter.setRenderHint(QPainter::Antialiasing);painter.setPen(_dotColor);painter.setBrush(_dotColor);//繪制點paintDot(painter);
}//計算繪制正方形區域
void Loading::caculate()
{_squareWidth=qMin(this->width(),this->height());float half=_squareWidth/2;_centerDistance=half-_maxDiameter/2-1;float gap=(_maxDiameter-_minDiameter)/(_count-1)/2;float angleGap=(float)360/_count;locationList.clear();radiiList.clear();for(int i=0;i<_count;i++){radiiList<<_maxDiameter/2-i*gap;float radian=qDegreesToRadians(-angleGap*i);locationList.append(Location(half+_centerDistance*qCos(radian),half-_centerDistance*qSin(radian)));}
}//繪制圓點
void Loading::paintDot(QPainter& painter)
{for(int i=0;i<_count;i++){painter.setPen(_dotColor);//半徑float radii=radiiList.at((_index+_count-i)%_count);//繪制圓點painter.drawEllipse(QPointF(locationList.at(i).x,locationList.at(i).y),radii,radii);//繪制正方形//painter.drawRect(locationList.at(i).x,locationList.at(i).y,radii,radii);//繪制文字//QFont font("Microsoft YaHei",radii*1.2,75);//painter.setFont(font);//painter.drawText(QPointF(locationList.at(i).x,locationList.at(i).y),u8"霞");}_index++;
}
#include "roundprogressbar.h"
#include "qmath.h"
#include <QPropertyAnimation>
#include <QDebug>RoundProgressBar::RoundProgressBar(QWidget *parent) :QWidget(parent),_value(0),_min(0),_max(100),_precision(0)
{//設置初始角度,順時針逆時針setdefault(90,true);//設置默認外圈寬度setOutterBarWidth(18);//設置默認內圈寬度setInnerBarWidth(16);//設置默認范圍setRange(0,100);//設置默認值setValue(75);//設置外圈顏色setOutterColor(QColor(233,248,248));//設置默認漸變色setInnerColor(QColor(49, 177, 190),QColor(133, 243, 244));//設置默認文字顏色setDefaultTextColor(QColor(49,177,190));//設置默認精度setPrecision(0);//設置內圈默認文字樣式setInnerDefaultTextStyle(RoundProgressBar::percent);
}RoundProgressBar::~RoundProgressBar()
{
}//********************************************** 外部接口 ****************************************
//設置初始角度,順時針逆時針
void RoundProgressBar::setdefault(int startAngle,bool clockWise)
{_startAngle=startAngle;_clockWise=clockWise;
}//設置外圈寬度
void RoundProgressBar::setOutterBarWidth(float width)
{_outterBarWidth=width;
}
//設置內圈寬度
void RoundProgressBar::setInnerBarWidth(float width)
{_innerBarWidth=width;
}//設置值的范圍
void RoundProgressBar::setRange(float min,float max)
{//todo 和value比較if(max<min){max=100;min=0;}else{_max=max;_min=min;}
}//設置當前值
void RoundProgressBar::setValue(float value)
{QPropertyAnimation* animation=new QPropertyAnimation(this,"_value");animation->setDuration(500);animation->setStartValue(_value);animation->setEndValue(value);animation->setEasingCurve(QEasingCurve::OutQuad);animation->start();
}void RoundProgressBar::_setValue(float value)
{_value=value;repaint();
}//設置外圈顏色
void RoundProgressBar::setOutterColor(const QColor& outterColor)
{_outterColor=outterColor;
}//設置內圈漸變色
void RoundProgressBar::setInnerColor(const QColor& startColor,const QColor& endColor)
{_startColor=startColor;_endColor=endColor;
}//設置內圈漸變色
void RoundProgressBar::setInnerColor(const QColor& startColor)
{_startColor=startColor;
}void RoundProgressBar::setDefaultTextColor(const QColor& textColor)
{_textColor=textColor;
}//設置控制
void RoundProgressBar::setControlFlags(int flags)
{this->_controlFlags|=flags;
}//設置顯示數字精度
void RoundProgressBar::setPrecision(int precision)
{_precision=precision;
}//********************************************** 內部繪制部分 ****************************************
void RoundProgressBar::resizeEvent(QResizeEvent *event)
{//根據內外圈寬度設置控件最小大小if(_outterBarWidth>_innerBarWidth)this->setMinimumSize(_outterBarWidth*8,_outterBarWidth*8);elsethis->setMinimumSize(_innerBarWidth*8,_innerBarWidth*8);//計算繪制正方形區域信息caculateSquare();
}void RoundProgressBar::paintEvent(QPaintEvent *)
{QPainter painter(this);painter.setRenderHint(QPainter::Antialiasing);//繪制外圈paintOutterBar(painter);//繪制內圈paintInnerBar(painter);//繪制外圈paintDot(painter);//繪制文字paintText(painter);
}//計算繪制正方形區域信息
void RoundProgressBar::caculateSquare()
{int minWidth=qMin(this->width(),this->height());float barWidth=qMax(_outterBarWidth,_innerBarWidth);_squareWidth=minWidth-barWidth-2;_squareStart=barWidth/2+1;_dotX=_squareStart+_squareWidth/2;_dotY=_squareStart;
}//繪制外圈
void RoundProgressBar::paintOutterBar(QPainter &painter)
{if(!(_controlFlags&outterCirle))return;QPen pen;pen.setWidth(_outterBarWidth);pen.setColor(_outterColor);painter.setPen(pen);QRectF rectangle(_squareStart,_squareStart,_squareWidth,_squareWidth);//從90度開始,逆時針旋轉painter.drawEllipse(rectangle);
}//繪制內圈
void RoundProgressBar::paintInnerBar(QPainter& painter)
{QPen pen;if(!(_controlFlags&linearColor))pen.setColor(_startColor);else{QLinearGradient gradient(0, 0, 0, _squareWidth);gradient.setColorAt(0, _startColor);gradient.setColorAt(1, _endColor);QBrush brush(gradient);pen.setBrush(brush);}pen.setWidth(_innerBarWidth);pen.setStyle(Qt::SolidLine);pen.setCapStyle(Qt::RoundCap);pen.setJoinStyle(Qt::RoundJoin);painter.setPen(pen);QRectF rectangle(_squareStart,_squareStart,_squareWidth,_squareWidth);//從90度開始,逆時針旋轉int startAngle=_startAngle*16;int spanAngle=(_value-_min)/(_max-_min)*360*16*(_clockWise?-1:1);painter.drawArc(rectangle,startAngle,spanAngle);
}//繪制裝飾圓點
void RoundProgressBar::paintDot(QPainter& painter)
{if(!(_controlFlags&decorateDot))return;//當bar寬度小于3時,便不再繪制裝飾圓點if(_innerBarWidth<3)return;painter.setPen(QColor(255,255,255));painter.setBrush(QColor(255,255,255));//區域為圓點繪制正方形區域painter.drawEllipse(_dotX-_innerBarWidth/6,_dotY-_innerBarWidth/6,_innerBarWidth/3,_innerBarWidth/3);
}//繪制默認內置文字
void RoundProgressBar::paintText(QPainter& painter)
{if(!(_controlFlags&defaultText))return;painter.setPen(_textColor);painter.setFont(QFont("Microsoft YaHei",22,75));switch (_innerDefaultTextStyle) {case value:painter.drawText(_squareStart,_squareStart,_squareWidth,_squareWidth,Qt::AlignCenter,QString::number(_value,'f',_precision));break;case valueAndMax:painter.drawText(_squareStart,_squareStart,_squareWidth,_squareWidth,Qt::AlignCenter,QString::number(_value,'f',_precision)+"/"+QString::number(_max,'f',_precision));break;case percent:painter.drawText(_squareStart,_squareStart,_squareWidth,_squareWidth,Qt::AlignCenter,QString::number(_value/_max*100,'f',_precision)+"%");break;default:break;}
}

三、下載鏈接

https://download.csdn.net/download/u013083044/88864197

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/697159.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/697159.shtml
英文地址,請注明出處:http://en.pswp.cn/news/697159.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【深入了解TensorFlow】TensorFlow的安裝與配置

【深入了解TensorFlow】TensorFlow的安裝與配置 TensorFlow的安裝與配置準備就緒:開始前的準備工作1. 確定您的硬件和操作系統2. 選擇安裝方式3. 創建虛擬環境(可選)安裝TensorFlow使用pip安裝使用conda安裝從源代碼編譯安裝配置TensorFlow導入TensorFlow模塊檢查安裝是否成…

Oracle 表被刪除或重命名后賬戶間的授權與同義詞關系

Oracle 表被刪除或重命名后賬戶間的授權與同義詞關系 情景一、 當數據表刪除后 數據表被刪除后&#xff0c;同義詞還是存在的&#xff0c;可以查看當前用戶下查看同義詞&#xff1a; -- 查看當前用戶下的同義詞 select * from user_synonyms但授權關系不在了&#xff0c;若重…

10 個 Linux 中超方便的 Bash 別名

1、 你有幾次遇到需要解壓 .tar 文件但無法記住所需的確切參數&#xff1f;別名可以幫助你&#xff01;只需將以下內容添加到 .bash_profile 中&#xff0c;然后使用 untar FileName 解壓縮任何 .tar 文件。 alias untartar -zxvf 2、 下載文件時&#xff0c;如果出現問題想要…

websocket與Socket的區別

概念講解 網絡&#xff1a;通俗意義上&#xff0c;也就是連接兩臺計算器 五層網絡模型&#xff1a;應用層、傳輸層、網絡層、數據鏈路層、物理層 應用層 (application layer)&#xff1a;直接為應用進程提供服務。應用層協議定義的是應用進程間通訊和交互的規則&#xff0c;不…

明明正常,卻不停return

明明正常&#xff0c;卻不停return if(!is); { return ; } 熬人

應急響應速查

最重要的&#xff1a;我是誰&#xff1f;我在哪&#xff1f;別人怎么進來的&#xff1f;我就是這個被挖礦被勒索的電腦。 分析項 &#xff1a; 一、了解大概的被入侵系統情況&#xff1a; 發現時間&#xff1f;怎么發現的&#xff1f;這臺機器有沒有人運維&#xff1f;平時還…

排序第三篇 直接插入排序

插入排序的基本思想是&#xff1a; 每次將一個待排序的記錄按其關鍵字的大小插入到前面已排好序的文件中的適當位置&#xff0c; 直到全部記錄插入完為止。 一 簡介 插入排序可分為2類 本文介紹 直接插入排序 它的基本操作是&#xff1a; 假設待排充序的記錄存儲在數組 R[1……

電路設計(27)——交通信號燈的multisim仿真

1.功能要求 使用數字芯片設計一款交通信號燈&#xff0c;使得&#xff1a; 主干道的綠燈時間為60S&#xff0c;紅燈時間為45S 次干道的紅燈時間為60S&#xff0c;綠燈時間為45S 主、次干道&#xff0c;綠燈的最后5S內&#xff0c;黃燈閃爍 使用數碼管顯示各自的倒計時時間。 按…

JavaScript 數組、遍歷

數組 多維數組&#xff1a;數組里面嵌套 一層數組為二維數組。一維數組的使用頻率是最高的。 如果數組訪問越界會返回undefined。 數組遍歷 數組方法Array.isArray() 這個方法可以去判定一個內容是否是數組。

AndroidStudio 2024-2-21 Win10/11最新安裝配置(Kotlin快速構建配置,gradle鏡像源)

AndroidStudio 2024 Win10/11最新安裝配置 教程目的&#xff1a; (從安裝到卸載) &#xff0c;針對Kotlin開發配置&#xff0c;gradle-8.2-src/bin下載慢&#xff0c;以及Kotlin構建慢的解決 好久沒玩AS了,下載發現裝個AS很麻煩,就覺得有必要出個教程了(就是記錄一下:嘻嘻) 因…

把一個對象變成可迭代對象的兩種方法,使用Symbol.iterator 和生成器Generator

方法一&#xff1a;自定義Symbol.iterator屬性 如果對象擁有[Symbol.iterator] 方法&#xff0c;改方法返回一個迭代器對象&#xff0c;就可以稱之為可迭代對象&#xff0c;注意迭代器是一個有 next 方法的對象 步驟如下 實現一個Symbol.iterator 鍵值是一個函數&#xff0c;…

java 時間格式 YYYY 于yyyy的區別

java formatDate 時間時&#xff0c;經常需要輸入格式比如 YYYYMMDD,yyyyMMdd 這兩個是有區別的 具體每個參數可以看下面

igolang學習1,dea的golang-1.22.0

參考&#xff1a;使用IDEA配置GO的開發環境備忘錄-CSDN博客 1.下載All releases - The Go Programming Language (google.cn) 2.直接next 3.window環境變量配置 4.idea的go插件安裝 5.新建go項目找不到jdk解決 https://blog.csdn.net/ouyang111222/article/details/1361657…

代碼隨想錄算法訓練營第40天| 343. 整數拆分、96.不同的二叉搜索樹

343. 整數拆分 完成 思路&#xff1a; dp數組存放正整數i拆分后的乘積最大值&#xff1b;i可以拆分為j和i-j&#xff0c;也可以是j和dp[i-j]。 代碼 class Solution {public int integerBreak(int n) {int[] dp new int[n1];dp[2] 1;// 推導i的拆分乘積最大值for (int i …

【js】無限虛擬列表的原理及實現

什么是虛擬列表 虛擬列表是長列表按需顯示思路的一種實現&#xff0c;即虛擬列表是一種根據滾動容器元素的可視區域來渲染長列表數據中某一個部分數據的技術。 簡而言之&#xff0c;虛擬列表指的就是「可視區域渲染」的列表。有三個概念需要了解一下&#xff1a; 視口容器元…

【linux】linux查看某個已經啟動進程的環境變量及命令行信息 /proc/${pid}/environ cmdline

隨便找一個進程 yeqiangyeqiang-MS-7B23:~$ ps aux | grep Vir yeqiang 3538 0.4 0.6 1797056 210332 ? Sl 08:38 0:06 /usr/lib/virtualbox/VirtualBox 查看命令行 yeqiangyeqiang-MS-7B23:~$ strings /proc/3538/cmdline /usr/lib/virtualbox/VirtualBox …

Swift基礎知識:17.Swift結構體

在 Swift 中&#xff0c;結構體&#xff08;Structures&#xff09;是一種用來封裝一組相關的數據和功能的數據類型。結構體是一種值類型&#xff0c;它在傳遞和賦值時會被復制&#xff0c;與類&#xff08;Class&#xff09;不同&#xff0c;類是引用類型&#xff0c;它在傳遞…

python專業版破解激活(超詳細)

python專業版破解激活 1.下載pycharm應用程序 這里我使用的版本是pycharm-professional-2023.3.2 下載pycharm程序的連接為&#xff1a; 百度網盤 請輸入提取碼 提取碼為&#xff1a;nym0 2.安裝 選擇安裝路徑 下一步 這里全選 下一步 這里直接點擊安裝就可&#xff0c;其…

Opencv(2)深淺拷貝與基本繪圖(c++python

Opencv(2)深淺拷貝與基本繪圖 文章目錄 Opencv(2)深淺拷貝與基本繪圖三、深淺拷貝四、HSV色域(1).意義(2).cvtColor()(3).inRange()(4).適應光線 三、深淺拷貝 淺拷貝是指當圖像之間進行賦值時&#xff0c;圖像數據并未發生復制&#xff0c;而是兩個對象都指向同一塊內存塊。 …

光伏氣象站:實現自動化、高精度的氣象監測

型號推薦&#xff1a;云境天合 TH-FGF9】光伏氣象站是一種基于光伏技術的氣象監測設備&#xff0c;它利用太陽能轉化為電能&#xff0c;為氣象站提供持續的電力供應&#xff0c;并實現自動化、高精度的氣象監測。 光伏氣象站的工作原理可以分為以下幾個部分&#xff1a; 光伏發…