irpas技术客

01表盘控件-01汽车仪表盘-gaugecar_Qt自定义控件大全+UI定制+输入法+视频监控+物联网

网络 4551

一、运行效果

二、功能特点 可设置范围值,支持负数值。可设置精确度,最大支持小数点后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 setOuterCircleColor(const QColor &outerCircleColor); //设置内圆背景颜色 void setInnerCircleColor(const QColor &innerCircleColor); //设置饼圆三种颜色 void setPieColorStart(const QColor &pieColorStart); void setPieColorMid(const QColor &pieColorMid); void setPieColorEnd(const QColor &pieColorEnd); //设置覆盖圆背景颜色 void setCoverCircleColor(const QColor &coverCircleColor); //设置刻度尺颜色 void setScaleColor(const QColor &scaleColor); //设置指针颜色 void setPointerColor(const QColor &pointerColor); //设置中心圆颜色 void setCenterCircleColor(const QColor &centerCircleColor); //设置文本颜色 void setTextColor(const QColor &textColor); //设置是否显示遮罩层 void setShowOverlay(bool showOverlay); //设置遮罩层颜色 void setOverlayColor(const QColor &overlayColor); //设置中间圆宽度 void setCircleWidth(int circleWidth); //设置饼图样式 void setPieStyle(const PieStyle &pieStyle); //设置指针样式 void setPointerStyle(const PointerStyle &pointerStyle); Q_SIGNALS: void valueChanged(int value); 四、使用示例 #pragma execution_character_set("utf-8") #include "frmgaugecar.h" #include "ui_frmgaugecar.h" #include "gaugecar.h" #include "qpropertyanimation.h" #include "qvariantanimation.h" #include "qmetaobject.h" #include "qdebug.h" frmGaugeCar::frmGaugeCar(QWidget *parent) : QWidget(parent), ui(new Ui::frmGaugeCar) { ui->setupUi(this); this->initForm(); } frmGaugeCar::~frmGaugeCar() { delete ui; } void frmGaugeCar::initForm() { //定时属性动画 animation = new QPropertyAnimation(ui->gaugeCar, "value"); animation->setDuration(800); //拿到所有动画类型 QMetaObject metaObject = QEasingCurve::staticMetaObject; QMetaEnum metaEnum = metaObject.enumerator(metaObject.indexOfEnumerator("Type")); int count = QEasingCurve::NCurveTypes - 1; for (int i = 0; i < count; ++i) { ui->cboxAnimationType->addItem(metaEnum.key(i)); } //设置默认的动画效果 ui->cboxAnimationType->setCurrentIndex(ui->cboxAnimationType->findText("OutBounce")); ui->horizontalSlider->setValue(88); //ui->gaugeCar->setCircleWidth(30); ui->ckAnimation->setChecked(true); ui->cboxPointerStyle->setCurrentIndex(1); } void frmGaugeCar::on_cboxPieStyle_currentIndexChanged(int index) { ui->gaugeCar->setPieStyle((GaugeCar::PieStyle)index); } void frmGaugeCar::on_cboxPointerStyle_currentIndexChanged(int index) { ui->gaugeCar->setPointerStyle((GaugeCar::PointerStyle)index); } void frmGaugeCar::on_horizontalSlider_valueChanged(int value) { //如果开启了动画则启动属性动画机制 if (ui->ckAnimation->isChecked()) { animation->stop(); animation->setStartValue(ui->gaugeCar->getValue()); animation->setEndValue(value); animation->start(); } else { ui->gaugeCar->setValue(value); } } void frmGaugeCar::on_cboxAnimationType_currentIndexChanged(int index) { animation->setEasingCurve((QEasingCurve::Type)index); }


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #可设置大刻度数量小刻度数量 #可设置开始旋转角度结束旋转角度 #可自由拓展各种渐变色各圆的半径