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.rhkb.cn/news/294383.html

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

相关文章

算法系列--递归,回溯,剪枝的综合应用(1)

&#x1f495;"对相爱的人来说&#xff0c;对方的心意&#xff0c;才是最好的房子。"&#x1f495; 作者&#xff1a;Lvzi 文章主要内容&#xff1a;算法系列–递归,回溯,剪枝的综合应用(1) 大家好,今天为大家带来的是算法系列--递归,回溯,剪枝的综合应用(1) 1.全排…

量化交易入门(三十八)CCI指标Python实现和回测

今天我们先单纯用CCI指标来完成策略的编写&#xff0c;后续我们会改进这个策略&#xff0c;将CCI指标和前面讲到的MACD和RSI相结合来优化&#xff0c;看看我们优化后的效果会不会更好。 一、量化策略 CCI指标在量化交易中的策略&#xff1a; 在以下情况下生成买入信号&#…

《第3选择》解决所有难题的关键思维 - 三余书屋 3ysw.net

第3选择&#xff1a;解决所有难题的关键思维 《第3选择》解决所有难题的关键思维&#xff0c;面对两难困境&#xff0c;从冲突中找到互相协同的出路 你好&#xff0c;今天我们要聊的这本书是《第3选择》&#xff0c;它出自美国著名作家史蒂芬科维之手。科维是国际上非常知名的…

RPA-财务对账邮件应用自动化(客户对账机器人)

《财务对账邮件应用自动化》&#xff0c;将会使用邮箱的SMTP服务&#xff0c;小北把资源包绑定在这篇博客了 Uibot (RPA设计软件)———机器人的小项目友友们可以参考小北的课前材料五博客~ (本博客中会有部分课程ppt截屏,如有侵权请及请及时与小北我取得联系~&#xff09; …

MySQL常见故障案例与优化介绍

前言 MySQL故障排查的意义在于及时识别并解决数据库系统中的问题&#xff0c;确保数据的完整性和可靠性&#xff1b;而性能优化则旨在提高数据库系统的效率和响应速度&#xff0c;从而提升用户体验和系统整体性能。这两方面的工作都对于保证数据库系统稳定运行、提升业务效率和…

1.5编写一个程序,输入梯形的上底,下底和高,输出梯形的面积。

1、编写一个程序,输入梯形的上底,下底和高,输出梯形的面积。 package com.kangning.web.controller.system;import java.util.Scanner;/*** 编写一个程序,输入梯形的上底,下底和高,输出梯形的面积。*/ public class CountArea {public static void main(String[] args) …

【智能家居项目】RT-Thread版本——DHT11获取温湿度 | MQTT上传到服务器 | 服务器控制外设

&#x1f431;作者&#xff1a;一只大喵咪1201 &#x1f431;专栏&#xff1a;《智能家居项目》 &#x1f525;格言&#xff1a;你只管努力&#xff0c;剩下的交给时间&#xff01; 这篇文章中&#xff0c;本喵将使用RT-Thread Studio来实现这个智能家居的项目&#xff0c;最终…

使用Git处理Github中提交有冲突的pull request

前言&#xff1a; 为什么要写这篇文章&#xff0c;因为前段时间有一个开源的github中的项目有一个朋友提交了一个pr看了下是帮忙优化了下代码&#xff08;十分感谢这位网友&#xff09;。但是他提交的pr刚好和我的项目有许多的冲突导致无法自动合并&#xff0c;在github中提示…

C++入门(2)

目录 3. C输入&输出 4. 缺省(默认)参数 4.1 缺省参数概念 4.2 缺省参数分类 全缺省参数 半缺省参数 5. 函数重载 5.1 函数重载概念 6. 引用 6.1 引用概念 6.2 引用特性 6.3 常引用 6.4 使用场景 6.5 传值、传引用效率比较 6.5.1 值和引用的作为返回值类型的性能比较 6.6 引…

一文入门Ubuntu22

目录 1.安装Ubuntu22 2.常用目录 3.常用指令 1.sudo 超级用户权限运行命令 2.ls 罗列当前文件信息 3.文件目录相关&#xff1a; 1.cd改变工作路径&#xff1a; 2.pwd 3.创建目录和文件&#xff1a; 4.which 5.ps 6.kill 7.ping 4.用户相关 5.ssh与scp 6.服务相关…

鸿蒙(HarmonyOS)ArkTs语言基础教程开发准备

本文档适用于HarmonyOS应用开发的初学者。通过构建一个简单的具有页面跳转/返回功能的应用&#xff08;如下图所示&#xff09;&#xff0c;快速了解工程目录的主要文件&#xff0c;熟悉HarmonyOS应用开发流程。 在开始之前&#xff0c;您需要了解有关HarmonyOS应用的一些基本概…

缺陷检测项目 | 使用小数据集训练实现锅炉水冷壁管表面视觉缺陷检测

项目应用场景 面向锅炉水冷璧管表面视觉缺陷检测场景&#xff0c;项目支持训练&#xff0c;使用小数据集就能够实现很好的缺陷检测效果。 项目效果&#xff1a; 项目细节 > 具体参见项目 README.md (1) 安装依赖&#xff0c;包括 gcForest、AutoKeras&#xff0c;然后安装其…

快速上手Pytrch爬虫之爬取某应图片壁纸

一、前置知识 1 爬虫简介 网络爬虫&#xff08;又被称作网络蜘蛛、网络机器人&#xff0c;在某些社区中也经常被称为网页追逐者)可以按照指定的规则&#xff08;网络爬虫的算法&#xff09;自动浏览或抓取网络中的信息。 1.1 Web网页存在方式 表层网页指的是不需要提交表单&…

JavaEE初阶之线程安全(一)

目录 题外话 正题 1.线程调度是随机的 2.修改共享数据 知识点 线程同步机制 线程异步机制 举例说明 synchronized() 知识点 举例说明 举例代码详解 死锁 举个例子: 代码 小结 题外话 这两天忽冷忽热的感冒了,昨天状态特别不好断更了一天,今天继续加油! 我会把…

远控桌面多任务并发文件保密传输

远程桌面文件传输是一个重要的功能&#xff0c;大多数远控都是用的桌面程序模式&#xff0c;利用系统自带复制粘贴拖拽文件拷贝功能&#xff0c;做一个ole调用对接&#xff0c;可以将很多控制权交给操作系统。 但我做的是浏览器版&#xff0c;浏览器是沙盒原理&#xff0c;为了…

LeetCode 738. 单调递增的数字

当且仅当每个相邻位数上的数字 x 和 y 满足 x < y 时&#xff0c;我们称这个整数是单调递增的。 给定一个整数 n &#xff0c;返回 小于或等于 n 的最大数字&#xff0c;且数字呈 单调递增 。 示例 1: 输入: n 10 输出: 9示例 2: 输入: n 1234 输出: 1234示例 3: 输入…

交通标志识别项目 | 基于Tensorflow+SSD实现道路交通标志识别

项目应用场景 面向智能驾驶或自动驾驶场景道路道路交通标志的识别&#xff0c;在交通标志识别的基础上为下一步的智能决策提供前提 项目效果&#xff1a; 项目细节 > 具体参见项目 README.md (1) 安装依赖 Python3.5、TensorFlow v0.12.0、Pickle、OpenCV-Python、Matplotl…

python笔记(9)Dictionary(字典)

目录 创建字典 取值 修改字典 删除 内置函数和方法 创建字典 字典键值和value用&#xff1a;隔开&#xff0c;键值是不可变的&#xff0c;而且必须是唯一的&#xff0c;值可以变&#xff0c;可以是任意类型 dict {key1 : value1, key2 : value2 } 1&#xff09;不允许同…

【面试八股总结】传输控制协议TCP(一)

一、什么是TCP协议 TCP是传输控制协议Transmission Control Protocol TCP 是面向连接的、可靠的、基于字节流的传输层通信协议。 面向连接的&#xff1a;每条TCP连接杜只能有两个端点&#xff0c;每一条TCP连接只能是点对点的&#xff08;一对一&#xff09;可靠的&#xff1a…