/** * 本控件来源于网络(原作者:lx100991(http://www.qtcn.org/bbs/read-htm-tid-62042.html )) * 1:增加设置背景色/第一第二第三颜色 * 2:增加设置文字字体及文字和刻度颜色 * 3:增加设置中间圆点颜色 * 4:修正当范围值中最小值为负数时的bug * 5:修正刻度值在三分之一阶段时切换不准确的bug * 6:增加一些完整性校验 */效果图
源码:
dialplot.cpp (8 K) 下载次数:308
dialplot.h (3 K) 下载次数:264 使用方法:复制代码#include "frmdialplot.h"#include "ui_frmdialplot.h"frmDialPlot::frmDialPlot(QWidget *parent) : QWidget(parent), ui(new Ui::frmDialPlot){ ui->setupUi(this); this->initForm();}frmDialPlot::~frmDialPlot(){ delete ui;}void frmDialPlot::initForm(){ int minValue = 0; int maxValue = 100; int value = minValue; ui->widget1->setUnit("km/h"); ui->widget1->setRange(minValue, maxValue); ui->widget1->setValue(value); ui->horizontalSlider1->setRange(minValue, maxValue); ui->horizontalSlider1->setValue(value); connect(ui->horizontalSlider1, SIGNAL(valueChanged(int)), ui->widget1, SLOT(setValue(int))); minValue = -50; maxValue = 150; value = minValue; ui->widget2->setTextColor(QColor(0, 0, 0)); ui->widget2->setBgColor(QColor(255, 255, 255)); ui->widget2->setFirstColor(QColor(112, 112, 112)); ui->widget2->setSecondColor(QColor(102, 205, 0)); ui->widget2->setThirdColor(QColor(135, 205, 254)); ui->widget2->setCenterColor(QColor(51, 51, 51)); ui->widget2->setUnit("℃"); ui->widget2->setRange(minValue, maxValue); ui->widget2->setValue(value); ui->horizontalSlider2->setRange(minValue, maxValue); ui->horizontalSlider2->setValue(value); connect(ui->horizontalSlider2, SIGNAL(valueChanged(int)), ui->widget2, SLOT(setValue(int)));}