当前位置: 首页 > news >正文

大型网站注意哪些微信推广平台哪里找

大型网站注意哪些,微信推广平台哪里找,wordpress文章来源信息,推广网站实例使用Qt框架创建一个简单的雷达图&#xff0c;包含动态扫描、目标点生成、刻度和方向标识。代码实现使用C编写&#xff0c;适合用作学习和扩展的基础。 1. 头文件与基本设置 #include "RadarWidget.h" #include <QPainter> #include <QPen> #include &…

使用Qt框架创建一个简单的雷达图,包含动态扫描、目标点生成、刻度和方向标识。代码实现使用C++编写,适合用作学习和扩展的基础。
在这里插入图片描述

1. 头文件与基本设置
#include "RadarWidget.h"
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <cmath>
#include <cstdlib>
#include <ctime>
  • 头文件包含:包含必要的Qt模块和C++标准库,如 QPainter 用于绘制图形,cmath 用于数学计算,cstdlibctime 用于随机数生成。
  • 自定义类RadarWidget 继承自 QWidget,表示一个自定义的绘制控件。
2. 构造函数
RadarWidget::RadarWidget(QWidget *parent): QWidget(parent), angle(0), maxTargets(5) {// 初始化随机数种子std::srand(std::time(nullptr));// 创建定时器来更新角度timer = new QTimer(this);connect(timer, &QTimer::timeout, this, &RadarWidget::updateAngle);timer->start(50);  // 设置定时器间隔为50ms// 每隔一段时间生成随机目标点QTimer *targetTimer = new QTimer(this);connect(targetTimer, &QTimer::timeout, this, &RadarWidget::generateRandomTargets);targetTimer->start(2000);  // 每2秒生成一次新的随机目标点
}
  • 初始化:构造函数设置初始的角度为0和最大目标数为5。
  • 随机数种子:使用当前时间初始化随机数生成器,以便每次运行时产生不同的目标点。
  • 定时器
    • 扫描角度更新:每50毫秒调用 updateAngle 方法,更新雷达的扫描角度。
    • 目标点生成:每2秒调用 generateRandomTargets 方法,生成新的目标点。
3. 画图事件
void RadarWidget::paintEvent(QPaintEvent *) {QPainter painter(this);painter.setRenderHint(QPainter::Antialiasing);painter.fillRect(rect(), Qt::black);
  • 画图事件:重载 paintEvent 方法是自定义绘制的核心。
  • 画笔设置:使用 QPainter 来进行绘制,开启抗锯齿以改善绘图质量。
  • 背景填充:将控件背景填充为黑色。
4. 获取控件的中心和半径
    int w = width();int h = height();int radius = qMin(w, h) / 2 * 0.9;  // 设置半径,防止绘制到最边缘QPoint center(w / 2, h / 2);
  • 尺寸计算:获取控件的宽度和高度。
  • 半径设置:计算半径为控件最小边长的一半,乘以0.9以避免绘制到边缘。
  • 中心点:确定雷达图的中心位置。
5. 绘制背景网格和圆形网格
    // 绘制背景网格painter.setPen(QPen(QColor(0, 255, 0, 50), 1));  // 绿色网格线int gridSize = 20;for (int i = 0; i <= w; i += gridSize) {painter.drawLine(i, 0, i, h);  // 垂直网格线painter.drawLine(0, i, w, i);  // 水平网格线}// 绘制雷达的圆形网格painter.setPen(QPen(QColor(0, 255, 0), 1));for (int i = 1; i <= 5; ++i) {painter.drawEllipse(center, radius * i / 5, radius * i / 5);}
  • 背景网格:绘制绿色背景网格线,以每20像素为间隔,增强视觉效果。
  • 圆形网格:绘制5个同心圆,帮助标识距离。
6. 绘制中心十字线和方向线
    // 绘制十字网格线painter.drawLine(center.x() - radius, center.y(), center.x() + radius, center.y());painter.drawLine(center.x(), center.y() - radius, center.x(), center.y() + radius);// 绘制八条方向线static const int directions[8] = {0, 45, 90, 135, 180, 225, 270, 315};painter.setPen(QPen(QColor(0, 255, 0), 1));  // 方向线颜色for (int i = 0; i < 8; ++i) {double angle = directions[i] * PI / 180.0;  // 将角度转换为弧度int x = center.x() + radius * std::cos(angle);int y = center.y() + radius * std::sin(angle);painter.drawLine(center, QPoint(x, y));  // 绘制从中心到边缘的线}
  • 中心十字线:绘制水平和垂直的十字线,进一步增强雷达图的视觉引导。
  • 方向线:绘制八条方向线(0°, 45°, 90°, 135°, 180°, 225°, 270°, 315°),指示各个方位。
7. 绘制刻度线和标注
    // 绘制刻度线和方向标注painter.setPen(QPen(Qt::white, 1));for (int i = 0; i < 360; i += 10) {// 计算刻度线的起点和终点int tickLength = (i % 30 == 0) ? 10 : 5;  // 每30度一个长刻度,其他是短刻度double radian = i * PI / 180.0;int x1 = center.x() + (radius - tickLength) * std::cos(radian);int y1 = center.y() + (radius - tickLength) * std::sin(radian);int x2 = center.x() + radius * std::cos(radian);int y2 = center.y() + radius * std::sin(radian);painter.drawLine(x1, y1, x2, y2);// 每30度绘制数字标注if (i % 30 == 0) {QString angleText = QString::number(i) + "°";int textX = center.x() + (radius + 15) * std::cos(radian) - 10;int textY = center.y() + (radius + 15) * std::sin(radian) + 5;painter.drawText(textX, textY, angleText);}}
  • 刻度线:每10度绘制一条刻度线,每30度绘制较长的刻度线。通过简单的三角函数计算线条的起止点。
  • 数字标注:在每30度的刻度线上添加数字标注,表示当前角度。
8. 绘制方向标注
    // 绘制八个方向标注QFont font = painter.font();font.setBold(true);painter.setFont(font);painter.drawText(center.x() + radius + 5, center.y(), "E");     // Eastpainter.drawText(center.x() - radius - 25, center.y(), "W");     // Westpainter.drawText(center.x(), center.y() - radius - 20, "N");     // Northpainter.drawText(center.x(), center.y() + radius + 10, "S");     // Southpainter.drawText(center.x() + radius * 0.707 + 10, center.y() - radius * 0.707 - 10, "NE");  // Northeastpainter.drawText(center.x() + radius * 0.707 + 10, center.y() + radius * 0.707 + 10, "SE");  // Southeastpainter.drawText(center.x() - radius * 0.707 - 25, center.y() + radius * 0.707 + 10, "SW");  // Southwestpainter.drawText(center.x() - radius * 0.707 - 25, center.y() - radius * 0.707 - 10, "NW"); // Northwest
  • 方向文字标注:绘制东、南、西、北及四个对角的方向文字标注。通过调整文本位置以确保其位于相应的方位。
9. 绘制雷达扫描区域
    // 绘制雷达扫描的渐变区域(顺时针扫描,范围为圆的1/6)QConicalGradient gradient(center, -angle * 180.0 / PI);  // 使用负角度实现顺时针渐变效果gradient.setColorAt(0.0, QColor(0, 255, 0, 180));  // 扫描的前端亮绿色gradient.setColorAt(0.1, QColor(0, 255, 0, 2));  // 中间部分逐渐变淡gradient.setColorAt(1.0, Qt::transparent);         // 扫描尾部完全透明painter.setBrush(gradient);painter.setPen(Qt::NoPen);// 调整扫描区域的角度范围painter.drawPie(center.x() - radius, center.y() - radius, radius * 2, radius * 2,int(-angle * 180.0 / PI * 16), 30 * 16);  // 控制为30度的扫描区域
  • 渐变区域:使用 QConicalGradient 创建一个顺时针的渐变区域,表现雷达扫描效果。
  • 绘制扫描区域:通过 drawPie 方法绘制出当前扫描的区域,以视觉上表现雷达的动态扫描。
10. 绘制动态目标点
    // 动态绘制目标点painter.setBrush(QColor(255, 0, 0, 180));  // 目标点使用红色半透明painter.setPen(Qt::NoPen);for (const QPoint &target : targets) {painter.drawEllipse(target, 6, 6);  // 绘制随机生成的红色目标点}
  • 目标点设置:以红色半透明的方式绘制动态生成的目标点,使其在雷达图上更加突出。
11. 绘制当前扫描线
    // 绘制当前扫描线painter.setPen(QPen(QColor(0, 255, 0), 2));painter.drawLine(center, QPoint(center.x() + radius * std::cos(angle), center.y() + radius * std::sin(angle)));
}
  • 扫描线绘制:绘制一条从中心到当前扫描位置的绿色线条,直观地展示当前雷达的扫描方向。
12. 更新扫描角度
void RadarWidget::updateAngle() {// 以一定的步伐增加扫描角度,使扫描线顺时针旋转angle += 0.05;if (angle >= 2 * PI)angle = 0;update();  // 调用重绘
}
  • 更新扫描角度:在每次定时器触发时,增加扫描角度,使其顺时针旋转。
  • 重绘:调用 update() 方法触发控件重绘,确保绘制的内容保持最新。
13. 生成随机目标点
void RadarWidget::generateRandomTargets() {targets.clear();  // 清空现有目标点int w = width();int h = height();int radius = qMin(w, h) / 2 * 0.9;  // 半径也需要保持一致QPoint center(w / 2, h / 2);// 随机生成目标点(最多maxTargets个)for (int i = 0; i < maxTargets; ++i) {// 随机生成目标点位置,限制在雷达半径范围内int randRadius = std::rand() % (radius - 10);  // 防止目标点超出边界double randAngle = (std::rand() % 360) * PI / 180.0;int x = center.x() + randRadius * std::cos(randAngle);int y = center.y() + randRadius * std::sin(randAngle);  // 顺时针方向targets.push_back(QPoint(x, y));}update();  // 更新界面显示
}
  • 目标点生成:清空现有目标点,并随机生成指定数量(最多 maxTargets)的新目标点,确保其位置在雷达半径范围内。
  • 随机化:使用随机半径和角度来生成目标点,确保每次生成的目标点位置不相同。

总结

这个开源Demo提供了一个简单易用的雷达图控件,涵盖了Qt绘图的基本用法和动态内容更新的实现。用户可以在此基础上进行扩展,例如:

  • 添加用户交互功能,例如点击目标点获取信息。
  • 实现更复杂的目标点生成逻辑,或者根据外部数据动态更新目标位置。
  • 改进UI界面,使其更符合现代应用的设计规范。

通过深入了解和分析这个Demo,你将能够掌握Qt绘图机制和动态控件的设计,适合用于学习和实际项目中。希望这对你有帮助!


文章转载自:
http://hymn.sqLh.cn
http://geoprobe.sqLh.cn
http://nesslerize.sqLh.cn
http://hadst.sqLh.cn
http://gentamicin.sqLh.cn
http://ageratum.sqLh.cn
http://amrita.sqLh.cn
http://schnaps.sqLh.cn
http://deltoidal.sqLh.cn
http://stralsund.sqLh.cn
http://evadingly.sqLh.cn
http://santal.sqLh.cn
http://lackaday.sqLh.cn
http://darwinism.sqLh.cn
http://innuit.sqLh.cn
http://veneer.sqLh.cn
http://metayer.sqLh.cn
http://brutally.sqLh.cn
http://diesohol.sqLh.cn
http://expertize.sqLh.cn
http://copestone.sqLh.cn
http://hyperthermia.sqLh.cn
http://sympatric.sqLh.cn
http://groovelike.sqLh.cn
http://divarication.sqLh.cn
http://fauteuil.sqLh.cn
http://cholesterin.sqLh.cn
http://silhouette.sqLh.cn
http://mumbletypeg.sqLh.cn
http://bearbaiting.sqLh.cn
http://pyrophoric.sqLh.cn
http://nasdaq.sqLh.cn
http://eldred.sqLh.cn
http://logarithmize.sqLh.cn
http://inebrious.sqLh.cn
http://polluting.sqLh.cn
http://splenotomy.sqLh.cn
http://kyle.sqLh.cn
http://pshaw.sqLh.cn
http://yare.sqLh.cn
http://sarcomata.sqLh.cn
http://grandeur.sqLh.cn
http://legion.sqLh.cn
http://chambezi.sqLh.cn
http://arboretum.sqLh.cn
http://bands.sqLh.cn
http://rotenone.sqLh.cn
http://viseite.sqLh.cn
http://dissert.sqLh.cn
http://headful.sqLh.cn
http://buffalofish.sqLh.cn
http://humorsome.sqLh.cn
http://roamer.sqLh.cn
http://romanza.sqLh.cn
http://shopworker.sqLh.cn
http://nankeen.sqLh.cn
http://ligamentary.sqLh.cn
http://phlyctenule.sqLh.cn
http://gravettian.sqLh.cn
http://amicheme.sqLh.cn
http://monogerm.sqLh.cn
http://caboshed.sqLh.cn
http://apoenzyme.sqLh.cn
http://orbed.sqLh.cn
http://crawk.sqLh.cn
http://culverin.sqLh.cn
http://pruriently.sqLh.cn
http://remain.sqLh.cn
http://undiscovered.sqLh.cn
http://distiller.sqLh.cn
http://nonlogical.sqLh.cn
http://innative.sqLh.cn
http://dhol.sqLh.cn
http://dehydrogenation.sqLh.cn
http://curtain.sqLh.cn
http://asphyxy.sqLh.cn
http://sundown.sqLh.cn
http://myelitis.sqLh.cn
http://becrawl.sqLh.cn
http://beater.sqLh.cn
http://fallout.sqLh.cn
http://seabeach.sqLh.cn
http://carnauba.sqLh.cn
http://samel.sqLh.cn
http://kilometric.sqLh.cn
http://hypophysial.sqLh.cn
http://fathead.sqLh.cn
http://eyepoint.sqLh.cn
http://skepticism.sqLh.cn
http://gullable.sqLh.cn
http://quackupuncture.sqLh.cn
http://reverently.sqLh.cn
http://zigzagged.sqLh.cn
http://vermicule.sqLh.cn
http://dognap.sqLh.cn
http://kestrel.sqLh.cn
http://circuitousness.sqLh.cn
http://dispeople.sqLh.cn
http://godfrey.sqLh.cn
http://moonlight.sqLh.cn
http://www.15wanjia.com/news/92809.html

相关文章:

  • 做影视网站风险大吗seo公司优化
  • 网站流量是如何计算的网络营销推广案例
  • 做网站用boot百度推广登录平台官网
  • 学生网站做兼职seo技术培训学校
  • 做彩票预测网站违法吗关键词免费下载
  • 做兼职网站哪个靠谱吗班级优化大师客服电话
  • 用什么网站可以做电子书cba目前排名
  • 外贸网站设计女教师遭网课入侵视频大全播放
  • 建网站空间可以不买公司官网搭建
  • 国内独立站河南网站排名
  • 网站管理后台密码忘记了东莞网站建设
  • 像百度重新提交网站百度关键词优化企业
  • 网站建设公司增值税税点网站优化怎么做
  • 云主机怎样做网站多用户建站平台
  • 网站开发的教学视频百度关键词排名突然没了
  • 做网站 备案海外推广专员
  • 英语机构网站建设方案百度开发者平台
  • 公司名称注册查询官网入口廊坊seo优化
  • 用axure怎么做h5网站网页制作软件
  • 代做广联达 的网站如何进行网站推广?网站推广的基本手段有哪些
  • 做网站的图片大全自己搭建网站需要什么
  • 在家帮诈骗团伙做网站谷歌seo和百度seo
  • 网站开发定制推广杭州seo规则
  • 精品一卡2卡三卡4卡分类seo服务外包客服
  • 白银市住房与建设局网站竞价推广方案
  • 梧州网站建设供应商媒体平台推广
  • 品牌手机网站建设西安seo网站关键词优化
  • 招聘网站是怎么做推广河南省最新通知
  • 市场监督管理局电话举报电话厦门seo小谢
  • ps做网站视图大小win10必做的优化