QT-飞机水平仪图标

QT-飞机水平仪图标

  • 一、演示效果
  • 二、关键程序
  • 三、下载链接

一、演示效果

请添加图片描述

二、关键程序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>#include <QtCore>
#include <QtGui>
#include <QDebug>
#include <QTableWidget>
#include <QHeaderView>#include "qFlightInstruments.h"
QADI::QADI(QWidget *parent): QWidget(parent)
{connect(this, SIGNAL(canvasReplot(void)), this, SLOT(canvasReplot_slot(void)));m_sizeMin = 200;m_sizeMax = 600;m_offset = 2;m_size = m_sizeMin - 2*m_offset;setMinimumSize(m_sizeMin, m_sizeMin);setMaximumSize(m_sizeMax, m_sizeMax);resize(m_sizeMin, m_sizeMin);setFocusPolicy(Qt::NoFocus);m_roll  = 0.0;m_pitch = 0.0;
}QADI::~QADI()
{}void QADI::canvasReplot_slot(void)
{update();
}void QADI::resizeEvent(QResizeEvent *event)
{m_size = qMin(width(),height()) - 2*m_offset;
}void QADI::paintEvent(QPaintEvent *)
{QPainter painter(this);QBrush bgSky(QColor(48,172,220));QBrush bgGround(QColor(247,168,21));QPen   whitePen(Qt::white);QPen   blackPen(Qt::black);QPen   pitchPen(Qt::white);QPen   pitchZero(Qt::green);whitePen.setWidth(2);blackPen.setWidth(2);pitchZero.setWidth(3);painter.setRenderHint(QPainter::Antialiasing);painter.translate(width() / 2, height() / 2);painter.rotate(m_roll);// FIXME: AHRS output left-hand valuesdouble pitch_tem = -m_pitch;// draw background{int y_min, y_max;y_min = m_size/2*-40.0/45.0;y_max = m_size/2* 40.0/45.0;int y = m_size/2*pitch_tem/45.;if( y < y_min ) y = y_min;if( y > y_max ) y = y_max;int x = sqrt(m_size*m_size/4 - y*y);qreal gr = atan((double)(y)/x);gr = gr * 180./3.1415926;painter.setPen(blackPen);painter.setBrush(bgSky);painter.drawChord(-m_size/2, -m_size/2, m_size, m_size,gr*16, (180-2*gr)*16);painter.setBrush(bgGround);painter.drawChord(-m_size/2, -m_size/2, m_size, m_size,gr*16, -(180+2*gr)*16);}// set maskQRegion maskRegion(-m_size/2, -m_size/2, m_size, m_size, QRegion::Ellipse);painter.setClipRegion(maskRegion);// draw pitch lines & marker{int x, y, x1, y1;int textWidth;double p, r;int ll = m_size/8, l;int     fontSize = 8;QString s;pitchPen.setWidth(2);painter.setFont(QFont("", fontSize));// draw linesfor(int i=-9; i<=9; i++) {p = i*10;s = QString("%1").arg(-p);if( i % 3 == 0 )l = ll;elsel = ll/2;if( i == 0 ) {painter.setPen(pitchZero);l = l * 1.8;} else {painter.setPen(pitchPen);}y = m_size/2*p/45.0 - m_size/2*pitch_tem/45.;x = l;r = sqrt(x*x + y*y);if( r > m_size/2 ) continue;painter.drawLine(QPointF(-l, 1.0*y), QPointF(l, 1.0*y));textWidth = 100;if( i % 3 == 0 && i != 0 ) {painter.setPen(QPen(Qt::white));x1 = -x-2-textWidth;y1 = y - fontSize/2 - 1;painter.drawText(QRectF(x1, y1, textWidth, fontSize+2),Qt::AlignRight|Qt::AlignVCenter, s);}}// draw markerint     markerSize = m_size/20;float   fx1, fy1, fx2, fy2, fx3, fy3;painter.setBrush(QBrush(Qt::red));painter.setPen(Qt::NoPen);fx1 = markerSize;fy1 = 0;fx2 = fx1 + markerSize;fy2 = -markerSize/2;fx3 = fx1 + markerSize;fy3 = markerSize/2;QPointF points[3] = {QPointF(fx1, fy1),QPointF(fx2, fy2),QPointF(fx3, fy3)};painter.drawPolygon(points, 3);QPointF points2[3] = {QPointF(-fx1, fy1),QPointF(-fx2, fy2),QPointF(-fx3, fy3)};painter.drawPolygon(points2, 3);}// draw roll degree lines{int     nRollLines = 36;float   rotAng = 360.0 / nRollLines;int     rollLineLeng = m_size/25;double  fx1, fy1, fx2, fy2;int     fontSize = 8;QString s;blackPen.setWidth(1);painter.setPen(blackPen);painter.setFont(QFont("", fontSize));for(int i=0; i<nRollLines; i++) {if( i < nRollLines/2 )s = QString("%1").arg(-i*rotAng);elses = QString("%1").arg(360-i*rotAng);fx1 = 0;fy1 = -m_size/2 + m_offset;fx2 = 0;if( i % 3 == 0 ) {fy2 = fy1 + rollLineLeng;painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2));fy2 = fy1 + rollLineLeng+2;painter.drawText(QRectF(-50, fy2, 100, fontSize+2),Qt::AlignCenter, s);} else {fy2 = fy1 + rollLineLeng/2;painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2));}painter.rotate(rotAng);}}// draw roll marker{int     rollMarkerSize = m_size/25;double  fx1, fy1, fx2, fy2, fx3, fy3;painter.rotate(-m_roll);painter.setBrush(QBrush(Qt::black));fx1 = 0;fy1 = -m_size/2 + m_offset;fx2 = fx1 - rollMarkerSize/2;fy2 = fy1 + rollMarkerSize;fx3 = fx1 + rollMarkerSize/2;fy3 = fy1 + rollMarkerSize;QPointF points[3] = {QPointF(fx1, fy1),QPointF(fx2, fy2),QPointF(fx3, fy3)};painter.drawPolygon(points, 3);}
}void QADI::keyPressEvent(QKeyEvent *event)
{switch (event->key()) {case Qt::Key_Left:m_roll -= 1.0;break;case Qt::Key_Right:m_roll += 1.0;break;case Qt::Key_Down:if(m_pitch>-90.)m_pitch -=1.0;break;case Qt::Key_Up:if(m_pitch<90.)m_pitch +=1.0;break;default:QWidget::keyPressEvent(event);break;}update();
}
QCompass::QCompass(QWidget *parent): QWidget(parent)
{connect(this, SIGNAL(canvasReplot(void)), this, SLOT(canvasReplot_slot(void)));m_sizeMin = 200;m_sizeMax = 600;m_offset = 2;m_size = m_sizeMin - 2*m_offset;setMinimumSize(m_sizeMin, m_sizeMin);setMaximumSize(m_sizeMax, m_sizeMax);resize(m_sizeMin, m_sizeMin);setFocusPolicy(Qt::NoFocus);m_yaw  = 0.0;m_alt  = 0.0;m_h    = 0.0;
}QCompass::~QCompass()
{}void QCompass::canvasReplot_slot(void)
{update();
}void QCompass::resizeEvent(QResizeEvent *event)
{m_size = qMin(width(),height()) - 2*m_offset;
}void QCompass::paintEvent(QPaintEvent *)
{QPainter painter(this);QBrush bgGround(QColor(48,172,220));QPen   whitePen(Qt::white);QPen   blackPen(Qt::black);QPen   redPen(Qt::red);QPen   bluePen(Qt::blue);QPen   greenPen(Qt::green);whitePen.setWidth(1);blackPen.setWidth(2);redPen.setWidth(2);bluePen.setWidth(2);greenPen.setWidth(2);painter.setRenderHint(QPainter::Antialiasing);painter.translate(width() / 2, height() / 2);// draw background{painter.setPen(blackPen);painter.setBrush(bgGround);painter.drawEllipse(-m_size/2, -m_size/2, m_size, m_size);}// draw yaw lines{int     nyawLines = 36;float   rotAng = 360.0 / nyawLines;int     yawLineLeng = m_size/25;double  fx1, fy1, fx2, fy2;int     fontSize = 8;QString s;blackPen.setWidth(1);painter.setPen(blackPen);for(int i=0; i<nyawLines; i++) {if( i == 0 ) {s = "N";painter.setPen(bluePen);painter.setFont(QFont("", fontSize*1.3));} else if ( i == 9 ) {s = "W";painter.setPen(blackPen);painter.setFont(QFont("", fontSize*1.3));} else if ( i == 18 ) {s = "S";painter.setPen(redPen);painter.setFont(QFont("", fontSize*1.3));} else if ( i == 27 ) {s = "E";painter.setPen(blackPen);painter.setFont(QFont("", fontSize*1.3));} else {s = QString("%1").arg(i*rotAng);painter.setPen(blackPen);painter.setFont(QFont("", fontSize));}fx1 = 0;fy1 = -m_size/2 + m_offset;fx2 = 0;if( i % 3 == 0 ) {fy2 = fy1 + yawLineLeng;painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2));fy2 = fy1 + yawLineLeng+4;painter.drawText(QRectF(-50, fy2, 100, fontSize+2),Qt::AlignCenter, s);} else {fy2 = fy1 + yawLineLeng/2;painter.drawLine(QPointF(fx1, fy1), QPointF(fx2, fy2));}painter.rotate(-rotAng);}}// draw S/N arrow{int     arrowWidth = m_size/5;double  fx1, fy1, fx2, fy2, fx3, fy3;fx1 = 0;fy1 = -m_size/2 + m_offset + m_size/25 + 15;fx2 = -arrowWidth/2;fy2 = 0;fx3 = arrowWidth/2;fy3 = 0;painter.setPen(Qt::NoPen);painter.setBrush(QBrush(Qt::blue));QPointF pointsN[3] = {QPointF(fx1, fy1),QPointF(fx2, fy2),QPointF(fx3, fy3)};painter.drawPolygon(pointsN, 3);fx1 = 0;fy1 = m_size/2 - m_offset - m_size/25 - 15;fx2 = -arrowWidth/2;fy2 = 0;fx3 = arrowWidth/2;fy3 = 0;painter.setBrush(QBrush(Qt::red));QPointF pointsS[3] = {QPointF(fx1, fy1),QPointF(fx2, fy2),QPointF(fx3, fy3)};painter.drawPolygon(pointsS, 3);}// draw yaw marker{int     yawMarkerSize = m_size/12;double  fx1, fy1, fx2, fy2, fx3, fy3;painter.rotate(-m_yaw);painter.setBrush(QBrush(QColor(0xFF, 0x00, 0x00, 0xE0)));fx1 = 0;fy1 = -m_size/2 + m_offset;fx2 = fx1 - yawMarkerSize/2;fy2 = fy1 + yawMarkerSize;fx3 = fx1 + yawMarkerSize/2;fy3 = fy1 + yawMarkerSize;QPointF points[3] = {QPointF(fx1, fy1),QPointF(fx2, fy2),QPointF(fx3, fy3)};painter.drawPolygon(points, 3);painter.rotate(m_yaw);}// draw altitude{int     altFontSize = 13;int     fx, fy, w, h;QString s;char    buf[200];w  = 130;h  = 2*(altFontSize + 8);fx = -w/2;fy = -h/2;blackPen.setWidth(2);painter.setPen(blackPen);painter.setBrush(QBrush(Qt::white));painter.setFont(QFont("", altFontSize));painter.drawRoundedRect(fx, fy, w, h, 6, 6);painter.setPen(bluePen);sprintf(buf, "ALT: %6.1f m", m_alt);s = buf;painter.drawText(QRectF(fx, fy+2, w, h/2), Qt::AlignCenter, s);sprintf(buf, "H: %6.1f m", m_h);s = buf;painter.drawText(QRectF(fx, fy+h/2, w, h/2), Qt::AlignCenter, s);}
}void QCompass::keyPressEvent(QKeyEvent *event)
{switch (event->key()) {case Qt::Key_Left:m_yaw -= 1.0;break;case Qt::Key_Right:m_yaw += 1.0;break;case Qt::Key_Down:m_alt -= 1.0;break;case Qt::Key_Up:m_alt += 1.0;break;case Qt::Key_W:m_h += 1.0;break;case Qt::Key_S:m_h -= 1.0;break;default:QWidget::keyPressEvent(event);break;}update();
}
QKeyValueListView::QKeyValueListView(QWidget *parent) : QTableWidget(parent)
{connect(this, SIGNAL(listUpdate(void)), this, SLOT(listUpdate_slot(void)));m_mutex = new QMutex();// set row & column numberssetRowCount(0);setColumnCount(2);// set no headers//verticalHeader()->hide();//horizontalHeader()->hide();QStringList htb = {"Name", "Value"};this->setHorizontalHeaderLabels(htb);// set last section is stretch-ableQHeaderView *HorzHdr = horizontalHeader();HorzHdr->setStretchLastSection(true);HorzHdr->resizeSection(0, 80);     // set first column width// disable table edit & focussetEditTriggers(QTableWidget::NoEditTriggers);setFocusPolicy(Qt::NoFocus);
}QKeyValueListView::~QKeyValueListView()
{delete m_mutex;
}void QKeyValueListView::listUpdate_slot(void)
{int                 i, n;ListMap::iterator   it;QColor              clCL1, clCL2;QColor              clB1, clB2;int                 fontSize = 8;int                 rowHeight = 20;clCL1 = QColor(0x00, 0x00, 0xFF);clCL2 = QColor(0x00, 0x00, 0x00);clB1  = QColor(0xFF, 0xFF, 0xFF);clB2  = QColor(0xE0, 0xE0, 0xE0);m_mutex->lock();n = m_data.size();setRowCount(n);setColumnCount(2);for(i=0, it=m_data.begin(); it!=m_data.end(); i++, it++) {// set name cellif( this->item(i, 0) != NULL ) {this->item(i, 0)->setText(it.key());} else {QTableWidgetItem* item = new QTableWidgetItem();item->setText(it.key());item->setTextColor(clCL1);if( i % 2 == 0 ) item->setBackgroundColor(clB1);else             item->setBackgroundColor(clB2);item->setFont(QFont("", fontSize));this->setItem(i, 0, item);}// set value cellif( this->item(i, 1) != NULL ) {this->item(i, 1)->setText(it.value());} else {QTableWidgetItem* item = new QTableWidgetItem();item->setText(it.value());item->setTextColor(clCL2);if( i % 2 == 0 ) item->setBackgroundColor(clB1);else             item->setBackgroundColor(clB2);item->setFont(QFont("", fontSize));this->setItem(i, 1, item);}setRowHeight(i, rowHeight);}m_mutex->unlock();
}

三、下载链接

https://download.csdn.net/download/u013083044/89067703

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/785988.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Oracle Solaris 11.3开工失败问题处理记录

1、故障现像 起初是我这有套RAC有点问题&#xff0c;我想重启1个节点&#xff0c;结果发现重启后该节点的IP能PING通&#xff0c;但SSH连不上去&#xff0c;对应的RAC服务也没有自动启动。 操作系统是solaris 11.3。由于该IP对应的主机是LDOM&#xff0c;于是我去主域上telnet…

【BlossomRPC】接入注册中心

文章目录 NacosZookeeper自研配置中心 RPC项目 配置中心项目 网关项目 这是BlossomRPC项目的最后一篇文章了&#xff0c;接入完毕注册中心&#xff0c;一个完整的RPC框架就设计完成了。 对于项目对注册中心的整合&#xff0c;其实我们只需要再服务启动的时候将ip/port/servic…

Qt6.6添加多媒体模块Multimedia报错问题

问题 QT包含多媒体模块Multimedia时提示未知的模块&#xff1a; error: Project ERROR: Unknown module(s) in QT: multimedia 在帮助文档中只可以找到QMediaPlayer类&#xff0c;但是点进去是空的&#xff0c;这是因为没有安装多媒体模块及对应的帮助文档。 解决 使用在线…

● 435. 无重叠区间 ● 763.划分字母区间 ● 56. 合并区间

● 435. 无重叠区间 class Solution:def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:if len(intervals)1:return 0intervalssorted(intervals,keylambda x:(x[0],x[1]))res0for i in range(1,len(intervals)):if intervals[i][0]<intervals[i-1][…

代码随想录算法训练营第41天|343. 整数拆分 |96.不同的二叉搜索树

代码随想录算法训练营第41天|343. 整数拆分 |96.不同的二叉搜索树 详细布置 今天两题都挺有难度&#xff0c;建议大家思考一下没思路&#xff0c;直接看题解&#xff0c;第一次做&#xff0c;硬想很难想出来。 343. 整数拆分 https://programmercarl.com/0343.%E6%95%B4%E6%…

【Go】十三、面向对象:方法

文章目录 1、面向对象2、结构体实例的创建3、结构体之间的转换4、方法5、结构体值拷贝6、方法的注意点7、方法和函数的区别8、跨包创建结构体实例 1、面向对象 Go的结构体struct ⇒ Java的Class类Go基于struct来实现OOP相比Java&#xff0c;Go去掉了方法重载、构造函数和析构函…

css- 4

1.浮动 1. 浮动最初用于实现文字环绕效果 2. 现在&#xff0c;浮动是主流的布局方式之一 1.1元素浮动之后的特点 元素浮动之后&#xff0c;称为浮动元素&#xff0c;具有如下特点&#xff1a; 1. 浮动元素脱离文档流 2. 多个浮动的元素会水平排列&#xff0c;一行放不下自动换…

Redis高级面试题-2024

说说你对Redis的理解 Redis是一个基于Key-Value存储结构的开源内存数据库&#xff0c;也是一种NoSQL数据库。 它支持多种数据类型&#xff0c;包括String、Map、Set、ZSet和List&#xff0c;以满足不同应用场景的需求。 Redis以内存存储和优化的数据结构为基础&#xff0c;提…

chatglm.cpp编译与执行

ChatGLM3介绍 ChatGLM3是由智谱AI和清华大学KEG实验室联合发布的对话预训练模型。作为第三代大型语言模型&#xff0c;ChatGLM3不仅理解和生成人类语言&#xff0c;还能执行代码、调用工具&#xff0c;并以markdown格式进行响应。其目标是打造更智能、更安全的代码解释器和工具…

【力扣一刷】代码随想录day27(39. 组合总和、40.组合总和II、131.分割回文串)

目录 【39. 组合总和】中等题 【40.组合总和II】中等题 【131. 分割回文串】中等题 【39. 组合总和】中等题 思路&#xff1a; 确定终止条件&#xff1a;sum target时记录路径并返回。剪枝&#xff1a;当前节点的路径之和已经大于sum就不可能再等于sum了&#xff0c;结束该分支…

16进制的字符串转byte[]数组 以及将字节数组转换成十六进制的字符串

16进制的字符串转byte[]数组 public class ClientString16 {@Testpublic void get16Str(){String str="48 47 12 00 14 12 16 08 15 0d 30 0f 02 30 30 30 30 30 30 30 30 30 30 00 c2";byte[] bytes = hexStringToByteArray(str);getBytetoString(bytes);//String …

【御控物联】JavaScript JSON结构转换(12):对象To数组——键值互换属性重组

文章目录 一、JSON结构转换是什么&#xff1f;二、核心构件之转换映射三、案例之《JSON对象 To JSON数组》四、代码实现五、在线转换工具六、技术资料 一、JSON结构转换是什么&#xff1f; JSON结构转换指的是将一个JSON对象或JSON数组按照一定规则进行重组、筛选、映射或转换…

【御控物联】JavaScript JSON结构转换(8):数组To数组——多层属性重组

文章目录 一、JSON结构转换是什么&#xff1f;二、案例之《JSON数组 To JSON数组》三、代码实现四、在线转换工具五、技术资料 一、JSON结构转换是什么&#xff1f; JSON结构转换指的是将一个JSON对象或JSON数组按照一定规则进行重组、筛选、映射或转换&#xff0c;生成新的JS…

Java

1.学生和老师都会有work方法&#xff0c;学生的工作是学习&#xff0c;老师的工作是教书&#xff0c;我利用了一个接口来实现&#xff1b; 2.同时&#xff0c;老师和学生都是人&#xff0c;并且都有姓名&#xff0c;姓名&#xff0c;年龄和身高等特征&#xff0c;我用了一个继承…

http协议补充

7.7实现http请求 class httprequest { public:void Deserialize(std::string content){while (true){auto pos content.find(sep);if (pos std::string::npos){break;}std::string temp content.substr(0, pos);if (temp.empty()){break;}req_header_.push_back(temp);cont…

轮播卡片切换实现

背景 如上图&#xff0c;实现一个轮播卡片能力&#xff0c;支持手动滑动&#xff0c;手动拖动&#xff0c;已经点击两端切换按钮。 实现 <template><div class"top-menu"><!-- Swiper --><div v-if"headerMenuList.length > 9" c…

并查集----格子游戏

并查集中最重要的是要搞懂&#xff1a; 不明白的可以拿纸自己先演示一番&#xff0c;find函数不仅能找到他们的祖先数&#xff0c;而且同时也能更新路径的子结点都等于祖先&#xff0c;然后以后寻找时会更加的方便&#xff01;

蓝桥杯单片机速成4-温度传感器DS18B20

目录 一、电路图 二、底层驱动代码 三、温度读取实现 四、实际使用 一、电路图 二、底层驱动代码 时序是单总线 我们需要修改的地方是单总线内部延时函数&#xff0c;改成 void Delay_OneWire(unsigned int t) { t*12; while(t--); } #ifndef __ONEWIRE_H #defi…

Unity TrailRenderer的基本了解

在Unity中&#xff0c;TrailRenderer组件用于在对象移动时创建轨迹效果。通常用于增强游戏中的动态物体&#xff0c;比如子弹、飞行道具或者角色移动时的拖尾效果。 下面来了解下它的基本信息。 1、创建 法1&#xff1a;通过代码创建 using UnityEngine;public class Trail…