forked from CUIT2014102073/QRoundProgressBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
419 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "GroupWidget.h" | ||
|
||
GroupWidget::GroupWidget(QWidget *parent) | ||
: QDialog(parent) | ||
{ | ||
//设置最小尺寸 | ||
setFixedSize(240,300); | ||
//去掉问号 | ||
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); | ||
//设置对话框标题 | ||
setWindowTitle(QStringLiteral("加群联系作者")); | ||
setStyleSheet("border-image:url(://Picture/Qt.png)"); | ||
} | ||
|
||
GroupWidget::~GroupWidget() | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef GROUPWIDGET_H | ||
#define GROUPWIDGET_H | ||
|
||
#include <QDialog> | ||
|
||
class GroupWidget : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
GroupWidget(QWidget *parent = 0); | ||
~GroupWidget(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "MainWidget.h" | ||
|
||
Widget::Widget(QWidget *parent) | ||
: QDialog(parent) | ||
{ | ||
//窗口基础设置 | ||
setFixedSize(300,350); | ||
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); | ||
setStyleSheet("background-color:rgb(68,68,68);"); | ||
|
||
//初始化控件 | ||
QPushButton* btn_Test=new QPushButton(); | ||
QPushButton* btn_GetCode=new QPushButton(); | ||
QVBoxLayout* mainLayout=new QVBoxLayout(); | ||
|
||
//这只按钮文字 | ||
btn_Test->setText(QStringLiteral("测试")); | ||
btn_GetCode->setText(QStringLiteral("获取源码")); | ||
|
||
//设置按钮高度 | ||
btn_Test->setFixedHeight(30); | ||
btn_GetCode->setFixedHeight(30); | ||
|
||
//设置按钮样式表 | ||
btn_Test->setStyleSheet("border-radius:4px;background-color:rgb(230,230,230);"); | ||
btn_GetCode->setStyleSheet("border-radius:4px;background-color:rgb(230,230,230);"); | ||
|
||
//环形进度条初始化 | ||
round_Bar=new QRoundProgressBar(); | ||
|
||
//环形进度条可选设置 | ||
do{ | ||
//round_Bar->SetStartAngle(-30); | ||
//round_Bar->SetEndAngle(210); | ||
//round_Bar->SetMaxRadius(100); | ||
//round_Bar->SetRingWidth(20); | ||
//round_Bar->SetIcomWidth(25); | ||
//round_Bar->SetCircularBorderColor(qRgb(255,0,0)); | ||
//round_Bar->SetInsideMaskColor(qRgb(0,255,0)); | ||
//round_Bar->SetRadialGradient(qRgb(10,10,10),qRgb(120,0,120)); | ||
//SlotBtnTest(); | ||
}while(0); | ||
|
||
|
||
//初始化并设置布局 | ||
QHBoxLayout* btnLayout=new QHBoxLayout(); | ||
btnLayout->setMargin(10); | ||
btnLayout->setSpacing(10); | ||
btnLayout->addWidget(btn_Test); | ||
btnLayout->addWidget(btn_GetCode); | ||
|
||
mainLayout->setMargin(20); | ||
mainLayout->setSpacing(0); | ||
mainLayout->addSpacing(20); | ||
mainLayout->addWidget(round_Bar); | ||
mainLayout->addLayout(btnLayout); | ||
setLayout(mainLayout); | ||
|
||
//添加信号与槽 | ||
connect(btn_Test,&QPushButton::clicked,this,&Widget::SlotBtnTest); | ||
connect(btn_GetCode,&QPushButton::clicked,this,&Widget::SlotBtnGetCode); | ||
} | ||
|
||
Widget::~Widget() | ||
{ | ||
} | ||
|
||
void Widget::SlotBtnTest() | ||
{ | ||
round_Bar->SetCurrPrograss(qrand()%100); | ||
} | ||
|
||
void Widget::SlotBtnGetCode() | ||
{ | ||
GroupWidget widget; | ||
widget.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef WIDGET_H | ||
#define WIDGET_H | ||
|
||
#include <QDialog> | ||
#include <QPushButton> | ||
#include <QVBoxLayout> | ||
#include <QHBoxLayout> | ||
|
||
#include "GroupWidget.h" | ||
#include "QRoundProgressBar.h" | ||
|
||
class Widget : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
QRoundProgressBar* round_Bar; | ||
|
||
public: | ||
Widget(QWidget *parent = nullptr); | ||
~Widget(); | ||
|
||
void SlotBtnTest(); | ||
void SlotBtnGetCode(); | ||
}; | ||
#endif // WIDGET_H |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
#include "QRoundProgressBar.h" | ||
|
||
QRoundProgressBar::QRoundProgressBar(QWidget *parent) : | ||
QWidget(parent) | ||
{ | ||
//给变量设置初始值-默认值 | ||
startAngle=-45; | ||
endAngle=225; | ||
ringWidth=20; | ||
maxRadius=110; | ||
iconWidth=15; | ||
currAngle=270; | ||
circularBorderColor=qRgb(120,120,120); | ||
insideMaskColor=qRgb(68,68,68); | ||
startGradientColor=qRgb(80,80,80); | ||
endGradientColor=qRgb(150,140,20); | ||
} | ||
|
||
void QRoundProgressBar::SetStartAngle(int value) | ||
{ | ||
startAngle=value; | ||
} | ||
|
||
void QRoundProgressBar::SetEndAngle(int value) | ||
{ | ||
endAngle=value; | ||
} | ||
|
||
void QRoundProgressBar::SetMaxRadius(int value) | ||
{ | ||
maxRadius=value; | ||
} | ||
|
||
void QRoundProgressBar::SetRingWidth(int value) | ||
{ | ||
ringWidth=value; | ||
} | ||
|
||
void QRoundProgressBar::SetIcomWidth(int value) | ||
{ | ||
iconWidth=value; | ||
} | ||
|
||
void QRoundProgressBar::SetCircularBorderColor(QRgb value) | ||
{ | ||
circularBorderColor=value; | ||
} | ||
|
||
void QRoundProgressBar::SetInsideMaskColor(QRgb value) | ||
{ | ||
insideMaskColor=value; | ||
} | ||
|
||
void QRoundProgressBar::SetRadialGradient(QRgb startColor,QRgb endColor) | ||
{ | ||
startGradientColor=startColor; | ||
endGradientColor=endColor; | ||
} | ||
|
||
void QRoundProgressBar::SetCurrPrograss(int value) | ||
{ | ||
currAngle=value; | ||
update(); | ||
} | ||
|
||
void QRoundProgressBar::paintEvent(QPaintEvent*) | ||
{ | ||
//初始化变量 | ||
QPainter painter(this); | ||
// 右移1位 相当于width()/2 | ||
painter.translate(width() >> 1, height() >> 1); | ||
//启动反锯齿 | ||
painter.setRenderHint(QPainter::Antialiasing); | ||
|
||
//绘制外圆 | ||
DrawOutSideCircle(painter); | ||
//绘制两个小圆外圆 | ||
DrawTwoSmallCircle(painter,0); | ||
//绘制圆环 | ||
DrawCircularRing(painter,0); | ||
//绘制两个小圆内圆 | ||
DrawTwoSmallCircle(painter,1); | ||
//绘制渐变色圆环 | ||
DrawGradientCircle(painter,maxRadius-1); | ||
//绘制内圆 | ||
DrawInSideCircle(painter); | ||
//绘制进度小圆 | ||
DrawBarIcon(painter); | ||
} | ||
|
||
void QRoundProgressBar::GradientArc(QPainter &painter,int radius,QRgb color) | ||
{ | ||
// 渐变色 | ||
QRadialGradient gradient(0, 0, radius); | ||
gradient.setColorAt(0, color); | ||
gradient.setColorAt(1.0, color); | ||
painter.setBrush(gradient); | ||
|
||
QRectF rect(-radius, -radius, radius << 1, radius << 1); | ||
QPainterPath path; | ||
path.arcTo(rect, startAngle, endAngle-startAngle); | ||
|
||
painter.setPen(Qt::NoPen); | ||
painter.drawPath(path); | ||
} | ||
|
||
void QRoundProgressBar::GradientFullArc(QPainter &painter,QPointF& point,int radius,QRgb color) | ||
{ | ||
// 渐变色 | ||
QRadialGradient gradient(0, 0, radius); | ||
gradient.setColorAt(0, color); | ||
gradient.setColorAt(1.0, color); | ||
painter.setBrush(gradient); | ||
painter.drawEllipse(point,radius,radius); | ||
} | ||
|
||
void QRoundProgressBar::DrawOutSideCircle(QPainter& painter) | ||
{ | ||
GradientArc(painter,maxRadius,circularBorderColor); | ||
} | ||
|
||
void QRoundProgressBar::DrawCircularRing(QPainter& painter,int) | ||
{ | ||
GradientArc(painter,maxRadius-1,startGradientColor); | ||
} | ||
|
||
void QRoundProgressBar::DrawTwoSmallCircle(QPainter& painter,int type) | ||
{ | ||
//计算小圆坐标 | ||
QPoint rightCircle(0,0); | ||
QPoint leftCircle(0,0); | ||
rightCircle.setY(-(qSin(startAngle*M_PI/180)*(maxRadius-ringWidth/2))); | ||
rightCircle.setX(qCos(startAngle*M_PI/180)*(maxRadius-ringWidth/2)+1); | ||
leftCircle.setX(-rightCircle.rx()); | ||
leftCircle.setY(rightCircle.ry()); | ||
if(type==0){ | ||
painter.drawEllipse(rightCircle,ringWidth/2,ringWidth/2); | ||
painter.drawEllipse(leftCircle,ringWidth/2,ringWidth/2); | ||
} | ||
else{ | ||
painter.drawEllipse(rightCircle,ringWidth/2-1,ringWidth/2-1); | ||
painter.drawEllipse(leftCircle,ringWidth/2-1,ringWidth/2-1); | ||
} | ||
} | ||
|
||
void QRoundProgressBar::DrawInSideCircle(QPainter& painter) | ||
{ | ||
QPointF point(0,0); | ||
GradientArc(painter,maxRadius-ringWidth+1,circularBorderColor); | ||
GradientFullArc(painter,point,maxRadius-ringWidth,insideMaskColor); | ||
//GradientFullArc(painter,maxRadius*3/4,qRgb(48,48,48)); | ||
} | ||
|
||
void QRoundProgressBar::DrawGradientCircle(QPainter& painter,int radius) | ||
{ | ||
QConicalGradient conicalGradient(QPointF(0, 0), endAngle+1); | ||
conicalGradient.setColorAt((360-qAbs(endAngle-startAngle)+currAngle)/360.0, endGradientColor); | ||
conicalGradient.setColorAt(1, startGradientColor); | ||
painter.setBrush(conicalGradient); | ||
QPainterPath path; | ||
QRectF rect(-radius, -radius, radius << 1, radius << 1); | ||
path.arcTo(rect, startAngle+currAngle, endAngle-startAngle-currAngle); | ||
painter.setPen(Qt::NoPen); | ||
painter.drawPath(path); | ||
} | ||
|
||
void QRoundProgressBar::DrawBarIcon(QPainter& painter) | ||
{ | ||
QPointF point(0,0); | ||
point.setX(point.x()+qCos((startAngle+currAngle)*M_PI/180)*(maxRadius-ringWidth/2)); | ||
point.setY(point.y()-qSin((startAngle+currAngle)*M_PI/180)*(maxRadius-ringWidth/2)); | ||
GradientFullArc(painter,point,iconWidth,endGradientColor); | ||
GradientFullArc(painter,point,iconWidth*0.6,startGradientColor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#ifndef QROUNDPROGRESSBAR_H | ||
#define QROUNDPROGRESSBAR_H | ||
|
||
#include <QLabel> | ||
#include <QTimer> | ||
#include <QtMath> | ||
#include <QObject> | ||
#include <QPainter> | ||
#include <QWidget> | ||
#include <QPixmap> | ||
#include <QVBoxLayout> | ||
|
||
class QRoundProgressBar : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
private: | ||
int startAngle; //起始角度 | ||
int endAngle; //结束角度 | ||
int ringWidth; //环宽度 | ||
int maxRadius; //大圆半径 | ||
int iconWidth; //图标的宽度 | ||
int currAngle; //当前进度条对应的角度 | ||
|
||
QRgb circularBorderColor; | ||
QRgb insideMaskColor; | ||
QRgb startGradientColor; | ||
QRgb endGradientColor; | ||
|
||
private: | ||
void DrawBarIcon(QPainter&); | ||
void GradientArc(QPainter&,int,QRgb); | ||
void GradientFullArc(QPainter&,QPointF&,int,QRgb); | ||
void DrawOutSideCircle(QPainter&); | ||
void DrawCircularRing(QPainter&,int); | ||
void DrawTwoSmallCircle(QPainter&,int); | ||
void DrawInSideCircle(QPainter&); | ||
void DrawGradientCircle(QPainter&,int); | ||
|
||
public: | ||
explicit QRoundProgressBar(QWidget *parent = nullptr); | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *event); | ||
|
||
public: | ||
//初始化调用函数 | ||
void SetStartAngle(int); //设置起始角度值 | ||
void SetEndAngle(int); //设置结束角度值 | ||
void SetMaxRadius(int); //设置圆环外圆半径 | ||
void SetRingWidth(int); //设置圆环宽度 | ||
void SetIcomWidth(int); //设置进度图标大小 | ||
void SetCircularBorderColor(QRgb); //设置圆环边框颜色 | ||
void SetInsideMaskColor(QRgb); //设置内圆遮罩颜色 | ||
void SetRadialGradient(QRgb,QRgb); //设置圆环渐变色 | ||
|
||
void SetCurrPrograss(int); //设置当前进度条进度值 | ||
|
||
}; | ||
|
||
#endif |
Oops, something went wrong.