01表盘控件-03百分比表盘-gaugepercent
原创
©著作权归作者所有:来自51CTO博客作者qq60b6d1b681847的原创作品,请联系作者获取转载授权,否则将追究法律责任
一、运行效果
二、功能特点
- 可设置范围值,支持负数值。
- 可设置精确度,最大支持小数点后3位。
- 可设置大刻度数量、小刻度数量。
- 可设置开始旋转角度、结束旋转角度。
- 可设置仪表盘的标题。
- 可设置外圆背景、内圆背景、饼圆三种颜色、刻度尺颜色、文字颜色。
- 自适应窗体拉伸、刻度尺、文字自动缩放。
- 可自由拓展各种渐变色、各圆的半径。
- 可设置百分比模式,自动计算值换算成百分比。
三、公共接口
public Q_SLOTS:
//设置范围值
void setRange(double minValue, double maxValue);
void setRange(int minValue, int maxValue);
//设置最大最小值
void setMinValue(double minValue);
void setMaxValue(double maxValue);
//设置目标值
void setValue(double value);
void setValue(int value);
//设置精确度
void setPrecision(int precision);
//设置主刻度数量
void setScaleMajor(int scaleMajor);
//设置小刻度数量
void setScaleMinor(int scaleMinor);
//设置开始旋转角度
void setStartAngle(int startAngle);
//设置结束旋转角度
void setEndAngle(int endAngle);
//设置圆弧颜色
void setArcColor(const QColor &arcColor);
//设置刻度尺颜色
void setScaleColor(const QColor &scaleColor);
//设置刻度值颜色
void setScaleNumColor(const QColor &scaleNumColor);
//设置文本颜色
void setTextColor(const QColor &textColor);
//设置标题颜色
void setTitleColor(const QColor &titleColor);
//设置基准颜色
void setBaseColor(const QColor &baseColor);
//设置背景颜色
void setBgColor(const QColor &bgColor);
//设置百分比模式
void setPercent(bool percent);
//设置标题
void setTitle(const QString &title);
Q_SIGNALS:
void valueChanged(int value);
四、使用示例
#pragma execution_character_set("utf-8")
#include "frmgaugepercent.h"
#include "ui_frmgaugepercent.h"
frmGaugePercent::frmGaugePercent(QWidget *parent) : QWidget(parent), ui(new Ui::frmGaugePercent)
{
ui->setupUi(this);
this->initForm();
}
frmGaugePercent::~frmGaugePercent()
{
delete ui;
}
void frmGaugePercent::initForm()
{
ui->widget->setStyleSheet("QWidget#widget{border-image: url(:/image/bg1.jpg);}");
QColor color = QColor(0, 255, 255);
ui->gaugePercent->setBaseColor(color);
ui->gaugePercent->setTitle("销售完成额");
connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->gaugePercent, SLOT(setValue(int)));
ui->horizontalSlider->setValue(88);
}