1 Star 0 Fork 3

Sean/QtGauges仪表控件

forked from 3YL/QtGauges仪表控件 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dialog.cpp 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
#include "dialog.h"
#include "ui_dialog.h"
#include <QTime>
#include <math.h>
#include <stdint.h>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
timer(this),
ui(new Ui::Dialog)
{
ui->setupUi(this);
// 50 Hz updates
timer.start(50);
connect(&timer, SIGNAL(timeout()), this, SLOT(onTimer()));
// Setup the displays
attitude.setupView(ui->attitudeView);
dial.setupView(ui->dialView);
vertLinearGauge1.setupView(ui->vertLinearView1);
vertLinearGauge1.setDualValue(true);
vertLinearGauge1.setDualValueLabel(true);
vertLinearGauge2.setupView(ui->vertLinearView2);
vertLinearGauge2.setTicksBothSides(true);
vertLinearGauge2.setDualValue(true);
horLinearGauge1.setupView(ui->horLinearView1);
horLinearGauge1.setDualValue(true);
horLinearGauge1.setDualValueLabel(true);
horLinearGauge2.setupView(ui->horLinearView2);
horLinearGauge2.setTicksBothSides(true);
horLinearGauge2.setDualValue(true);
horLinearGauge1.setHorizontal(true);
horLinearGauge2.setHorizontal(true);
// We need to adjust scenes after the window is finished being built
// as we need the size data. This is the simplest method I can find
QTimer::singleShot(0, this, SLOT(adjustScenes()));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::resizeEvent(QResizeEvent * event)
{
adjustScenes();
}
void Dialog::adjustScenes(void)
{
attitude.setupView(ui->attitudeView);
dial.setupView(ui->dialView);
vertLinearGauge1.setupView(ui->vertLinearView1);
vertLinearGauge2.setupView(ui->vertLinearView2);
horLinearGauge1.setupView(ui->horLinearView1);
horLinearGauge2.setupView(ui->horLinearView2);
}
void Dialog::onTimer(void)
{
QTime time = QTime::currentTime();
uint32_t msecs = 1000*time.second() + time.msec();
// 10 second period
msecs %= 10000;
// convert to 0 to 2PI
double input = 2.0*3.1415926535897932384626433832795*msecs/10000.0;
double input2 = input;
// A number from 0 to 100 that moves sinusoidally with time
input = 50.0*sin(input) + 50.0;
input2 = 50.0*cos(input2) + 50.0;
attitude.setAngles(input-50,input-50,input*3.6);
dial.setReading(input, input*1000);
horLinearGauge1.setDualReadings(input, input2);
horLinearGauge2.setDualReadings(input, input2);
vertLinearGauge1.setDualReadings(input, input2);
vertLinearGauge2.setDualReadings(input, input2);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/blackfire531/qt-gauge-control.git
git@gitee.com:blackfire531/qt-gauge-control.git
blackfire531
qt-gauge-control
QtGauges仪表控件
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385