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

Qt绘制网格和曲线

绘制网格:

void Widget::drawGrid(QPainter &p, QRect &windRect)
{QRect   rect(windRect.left()+m_margins.left(),windRect.top()+m_margins.top(),windRect.width()-m_margins.left()-m_margins.right(),windRect.height()-m_margins.top()-m_margins.bottom());if (!rect.isValid())return;QPen    penDot(Qt::DotLine);penDot.setColor(Qt::gray);QPen    penSolid(Qt::SolidLine);penSolid.setColor(Qt::black);
//    pen.setColor(this->palette().light().color());p.setPen(penSolid);p.drawRect(rect.adjusted(0,0,-1,-1));int     Xpos;qreal   Xvalue;QString xlab;QFontMetrics    textSize(this->font());QRect   textRect;for(int i=0;i<=m_XTicks;i++){Xpos=rect.left()+i*m_xRatio; //Xvalue=m_xmin+i*m_xspan/m_XTicks;//p.setPen(penDot);p.drawLine(Xpos,rect.top(),Xpos,rect.bottom());p.setPen(penSolid);p.drawLine(Xpos,rect.bottom(),Xpos,rect.bottom()+5);xlab=QString::asprintf("%.1f",Xvalue);textRect=textSize.boundingRect(xlab);//得到字符串的rectp.drawText(Xpos-textRect.width()/2,rect.bottom()+5+textRect.height(),xlab);}xlab="time(sec)";textRect=textSize.boundingRect(xlab);//得到字符串的rectp.drawText(rect.left()+(rect.width()-textRect.width())/2,windRect.bottom()-textRect.height()/2,xlab);xlab="曲线绘图";textRect=textSize.boundingRect(xlab);//得到字符串的rectp.drawText(rect.left()+(rect.width()-textRect.width())/2,(m_margins.top()-textRect.height())/2+textRect.height(),xlab);int     Ypos;qreal   Yvalue;QString ylab;for(int i=0;i<=m_YTicks;i++){Ypos=rect.bottom()-i*m_yRatio; //Yvalue=m_ymin+i*m_yspan/m_YTicks;//p.setPen(penDot);p.drawLine(rect.left(),Ypos,rect.right(),Ypos);p.setPen(penSolid);p.drawLine(rect.left()-5,Ypos,rect.left(),Ypos);ylab=QString::asprintf("%.1f",Yvalue);textRect=textSize.boundingRect(ylab);//得到字符串的rectp.drawText(rect.left()-10-textRect.width(),Ypos+textRect.height()/2,ylab);}ylab="函数值";textRect=textSize.boundingRect(ylab);//得到字符串的rectp.save();p.translate(0,windRect.height()/2); //平移到左侧中心p.rotate(-90);//逆时针旋转90度,变成正北为X轴,正东为Y轴p.drawText(-textRect.width()/2,(m_margins.left()-textRect.height())/2,ylab);p.restore();
}

绘制曲线:

void Widget::drawCurve(QPainter &p, QRect &windRect)
{QPolygon    curve(m_points.count());for(int i=0;i<m_points.count();i++)curve[i]=m_points[i];QPen    penSolid(Qt::SolidLine);penSolid.setColor(Qt::blue);penSolid.setWidth(2);p.setPen(penSolid);p.drawPolyline(curve);
}

http://www.lryc.cn/news/227509.html

相关文章:

  • 2023-11-12
  • [工业自动化-16]:西门子S7-15xxx编程 - 软件编程 - 西门子仿真软件PLCSIM
  • 运行npm install卡住不动的几种解决方案
  • [Android]_[初级]_[配置gradle的环境变量设置安装位置]
  • docker更改存储目录原因及方案
  • HTTPS的工作流程
  • C++语言的广泛应用领域
  • Lambertian模型(完美漫反射)
  • MATLAB的编程与应用,匿名函数、嵌套函数、蒙特卡洛法的掌握与使用
  • NFS服务器的搭建
  • 安卓Frida 常用脚本
  • 机器学习数据预处理——Word2Vec的使用
  • 面试算法常考题之-------逆波兰式合集
  • 独热编码和Word2Vec的区别
  • RestTemplate.postForEntity 方法进行 HTTP POST 请求
  • 盘点双11!阿里妈妈助这些品牌短视频赢增长!
  • 内网可达网段探测netspy- Mac环境
  • Liunx命令汇总
  • 自动控制原理--面试问答题
  • Word2Vec的缺点
  • vue如何解决跨域?原理?
  • Conda executable is not found 三种问题解决
  • Thinkphp8 - 连接多个数据库
  • Linux如何修改主机名(hostname)(亲测可用)
  • 银河麒麟等 Linux系统 安装 .net 3.1,net 6及更高版本的方法
  • Unity 使用INI文件存储数据或配置参数预设
  • clouldcompare工具使用
  • 在vue3中使用Element-plus的图标
  • 图扑智慧农业:农林牧数据可视化监控平台
  • js 加解密 jsencrypt(非对称加密 rsa)