金华市金东区建设局网站上海软件外包公司有哪些
news/
2025/9/30 15:40:40/
文章来源:
金华市金东区建设局网站,上海软件外包公司有哪些,美容院网站模板,wordpress 图片自适应1.概述
QwtPlotMarker类是Qwt绘图库中用于在图表上绘制标记的类。标记可以是垂直或水平线、直线、文本或箭头等。它可用于标记某个特定的位置、绘制参考线或注释信息。
以下是类继承关系图#xff1a; 2.常用方法
设置标记的坐标。传入x和y坐标值#xff0c;标记将被放置在…1.概述
QwtPlotMarker类是Qwt绘图库中用于在图表上绘制标记的类。标记可以是垂直或水平线、直线、文本或箭头等。它可用于标记某个特定的位置、绘制参考线或注释信息。
以下是类继承关系图 2.常用方法
设置标记的坐标。传入x和y坐标值标记将被放置在指定的位置。
setValue(double x, double y)
分别设置标记的x和y坐标。可以单独调用这些方法来更改标记的位置。
setXValue(double x)和setYValue(double y)
设置标记的文本标签。
void setLabel (const QwtText )设置标记的线条样式。可以选择实线、虚线和点线等样式。
setLineStyle(QwtPlotMarker::LineStyle style)
设置标记的线条画笔。传入一个QPen类型的对象用于设定线条的颜色、宽度等属性。
setLinePen(const QPen pen)
设置标记的符号样式。传入一个QwtSymbol类型的对象用于设定标记的符号样式。
setSymbol(QwtSymbol *symbol)
将标记附加到或从QwtPlot中分离。attach()方法用于将标记添加到QwtPlot图表中而detach()方法则用于从图表中移除标记。
attach(QwtPlot *plot)和detach()
3.代码示例
画了两根曲线sin和cos中间绘制了两个标记QwtPlotMarker一个代表0轴一个代表(1,0)点。 #include mainwindow.h
#include ui_mainwindow.h
#include qwt_plot.h
#include qwt_plot_curve.h
#include qwt_text.h
#include qwt_legend.h
#include qwt_symbol.h
#include qwt_plot_marker.hMainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui-setupUi(this);QwtPlot *plot new QwtPlot(QwtText(sin and cos),this);//设置背景色plot-setCanvasBackground(QBrush(QColor(Qt::white)));//添加图例QwtLegend *legend new QwtLegend();plot-insertLegend(legend);//设置坐标轴标题plot-setAxisTitle(QwtAxis::YLeft,QwtText(Y坐标轴));plot-setAxisTitle(QwtAxis::XBottom,QwtText(X坐标轴));plot-setAxisScale(QwtAxis::YLeft, -1, 1);//设置左Y轴范围plot-setAxisScale(QwtAxis::XBottom, 0, 2);//设置左Y轴范围// add curves1QwtPlotCurve *curve1 new QwtPlotCurve( cos );curve1-setRenderHint( QwtPlotItem::RenderAntialiased );curve1-setPen( Qt::blue );//curve1-setBrush(QBrush(QColor(Qt::red)));curve1-setLegendAttribute( QwtPlotCurve::LegendShowLine );curve1-setYAxis( QwtAxis::YLeft );curve1-setStyle(QwtPlotCurve::Lines);curve1-attach( plot );// add curves2QwtPlotCurve *curve2 new QwtPlotCurve( sin );curve2-setRenderHint( QwtPlotItem::RenderAntialiased );curve2-setPen( Qt::gray );//curve3-setBrush(QBrush(QColor(Qt::black)));curve2-setLegendAttribute( QwtPlotCurve::LegendShowLine );curve2-setYAxis( QwtAxis::YLeft );curve2-setStyle(QwtPlotCurve::Lines);curve2-attach( plot );int numPoints 100;QVectorQPointF points1;QVectorQPointF points2;for (int i 0; i numPoints; i) {double x 2*i / (double)(numPoints - 1); // x范围从0到2double y sin(2 * M_PI * x); // 计算sin函数的y值double y2 cos(2 * M_PI * x); // 计算sin函数的y值points1.append(QPointF(x, y));points2.append(QPointF(x, y2));}curve1-setSamples(points2);curve2-setSamples(points1);// 创建水平参考线标记QwtPlotMarker *lineMarker new QwtPlotMarker();lineMarker-setLabel(QwtText(zero axis)); // 设置标记的文本标签lineMarker-setLabelAlignment(Qt::AlignRight | Qt::AlignTop); // 设置标签的对齐方式lineMarker-setLabelOrientation(Qt::Horizontal); // 设置标签的方向为水平lineMarker-setLineStyle(QwtPlotMarker::HLine); // 设置标记的线条样式为水平线lineMarker-setLinePen(Qt::red, 2.0); // 设置标记的线条颜色和宽度lineMarker-setValue(0.0, 0.0); // 设置标记的坐标位置// 创建文本标记QwtPlotMarker *textMarker new QwtPlotMarker();textMarker-setLabel(QwtText((1,0))); // 设置标记的文本标签textMarker-setLabelAlignment(Qt::AlignCenter | Qt::AlignTop); // 设置标签的对齐方式textMarker-setLabelOrientation(Qt::Horizontal); // 设置标签的方向为水平textMarker-setLineStyle(QwtPlotMarker::NoLine); // 设置标记没有线条textMarker-setXValue(1); // 设置标记的x坐标textMarker-setYValue(0); // 设置标记的y坐标// 将标记附加到QwtPlot中lineMarker-attach(plot);textMarker-attach(plot);// finally, refresh the plotplot-replot();ui-verticalLayout-addWidget(plot);
}MainWindow::~MainWindow()
{delete ui;
}4.相关参考
Qwt QwtPlotCurve类详解-CSDN博客
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/923008.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!