QT-飞机水平仪图标

2024-04-02 01:52
文章标签 qt 图标 飞机 水平仪

本文主要是介绍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

这篇关于QT-飞机水平仪图标的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/868671

相关文章

Qt中QGroupBox控件的实现

《Qt中QGroupBox控件的实现》QGroupBox是Qt框架中一个非常有用的控件,它主要用于组织和管理一组相关的控件,本文主要介绍了Qt中QGroupBox控件的实现,具有一定的参考价值,感兴趣... 目录引言一、基本属性二、常用方法2.1 构造函数 2.2 设置标题2.3 设置复选框模式2.4 是否

QT进行CSV文件初始化与读写操作

《QT进行CSV文件初始化与读写操作》这篇文章主要为大家详细介绍了在QT环境中如何进行CSV文件的初始化、写入和读取操作,本文为大家整理了相关的操作的多种方法,希望对大家有所帮助... 目录前言一、CSV文件初始化二、CSV写入三、CSV读取四、QT 逐行读取csv文件五、Qt如何将数据保存成CSV文件前言

Qt中QUndoView控件的具体使用

《Qt中QUndoView控件的具体使用》QUndoView是Qt框架中用于可视化显示QUndoStack内容的控件,本文主要介绍了Qt中QUndoView控件的具体使用,具有一定的参考价值,感兴趣的... 目录引言一、QUndoView 的用途二、工作原理三、 如何与 QUnDOStack 配合使用四、自

Qt spdlog日志模块的使用详解

《Qtspdlog日志模块的使用详解》在Qt应用程序开发中,良好的日志系统至关重要,本文将介绍如何使用spdlog1.5.0创建满足以下要求的日志系统,感兴趣的朋友一起看看吧... 目录版本摘要例子logmanager.cpp文件main.cpp文件版本spdlog版本:1.5.0采用1.5.0版本主要

macOS无效Launchpad图标轻松删除的4 种实用方法

《macOS无效Launchpad图标轻松删除的4种实用方法》mac中不在appstore上下载的应用经常在删除后它的图标还残留在launchpad中,并且长按图标也不会出现删除符号,下面解决这个问... 在 MACOS 上,Launchpad(也就是「启动台」)是一个便捷的 App 启动工具。但有时候,应

Qt 中 isHidden 和 isVisible 的区别与使用小结

《Qt中isHidden和isVisible的区别与使用小结》Qt中的isHidden()和isVisible()方法都用于查询组件显示或隐藏状态,然而,它们有很大的区别,了解它们对于正确操... 目录1. 基础概念2. 区别清见3. 实际案例4. 注意事项5. 总结1. 基础概念Qt 中的 isHidd

QT移植到RK3568开发板的方法步骤

《QT移植到RK3568开发板的方法步骤》本文主要介绍了QT移植到RK3568开发板的方法步骤,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录前言一、获取SDK1. 安装依赖2. 获取SDK资源包3. SDK工程目录介绍4. 获取补丁包二

Qt把文件夹从A移动到B的实现示例

《Qt把文件夹从A移动到B的实现示例》本文主要介绍了Qt把文件夹从A移动到B的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录如何移动一个文件? 如何移动文件夹(包含里面的全部内容):如何删除文件夹:QT 文件复制,移动(

Python使用PIL库将PNG图片转换为ICO图标的示例代码

《Python使用PIL库将PNG图片转换为ICO图标的示例代码》在软件开发和网站设计中,ICO图标是一种常用的图像格式,特别适用于应用程序图标、网页收藏夹图标等场景,本文将介绍如何使用Python的... 目录引言准备工作代码解析实践操作结果展示结语引言在软件开发和网站设计中,ICO图标是一种常用的图像

Qt实现发送HTTP请求的示例详解

《Qt实现发送HTTP请求的示例详解》这篇文章主要为大家详细介绍了如何通过Qt实现发送HTTP请求,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1、添加network模块2、包含改头文件3、创建网络访问管理器4、创建接口5、创建网络请求对象6、创建一个回复对