qcustomplot 怎样设置坐标轴刻度

qcustomplot 怎样设置坐标轴刻度,第1张

MouseEvent->pos()可以获得相对于viewport()的坐标pos,

然后

size1=customPlot->viewport()size();

size2=customPlot->axisRect()->size();

pos-(size1-size2)/ 2就可以获得鼠标点击位置的坐标

1、怎样配置使用就不细说了,官网上代码和文档都是有的

2、关键函数与设置属性的介绍

//设置显示的大小和位置

ui->PressDraw->setGeometry(QRect(30,30,650,350));

//设置需要显示的坐标轴

ui->PressDraw->xAxis2->setVisible(true);

ui->PressDraw->xAxis2->setTickLabels(true);

ui->PressDraw->xAxis->setVisible(false);

ui->PressDraw->xAxis->setTickLabels(false);

//添加箭头

ui->PressDraw->xAxis2->setUpperEnding(QCPLineEnding::esSpikeArrow);

ui->PressDraw->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);

//纵坐标反转找了好久才知道这个函数

ui->PressDraw->yAxis->setRangeReversed(true);

[cpp] view plain copy

//设置坐标轴单位名称

ui->PressDraw->xAxis2->setLabel(codec->toUnicode("压力(MPa)"));

//右上标签显示

ui->PressDraw->legend->setVisible(true);

ui->PressDraw->legend->setFont(QFont("Helvetica",9));

ui->PressDraw->legend->setBrush(QBrush(QColor(255,255,255,210)));//210透明度

ui->PressDraw->legend->setSelectableParts(QCPLegend::spItems);

ui->PressDraw->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignRight);//标签位置

//移动和放缩

ui->PressDraw->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

//向绘图区域QCustomPlot添加一条曲线

ui->PressDraw->addGraph(ui->PressDraw->yAxis,ui->PressDraw->xAxis);

ui->PressDraw->graph(i)->setData(y,x);//绘图的数据

ui->PressDraw->graph(i)->setName(codec->toUnicode("曲线%1")arg(i));

ui->PressDraw->graph(i)->setScatterStyle(m_StyleChoiceat(i));//点样式

ui->PressDraw->graph(i)->setPen(m_PenChoiceat(i));//画笔

ui->PressDraw->graph(i)->rescaleAxes();//重绘

3、很多标签是有槽函数的,可根据需要进行编写。比如可以通过点击“深度”,实现单位换算。以及右上标签"曲线0",实现需要的功能,我这里是点击实现数据的更改和查看。这里列出一些槽函数作参考。

//双击修改坐标轴标签设置单位

connect(ui->PressDraw, SIGNAL(axisDoubleClick(QCPAxis,QCPAxis::SelectablePart,QMouseEvent)),

this, SLOT(axisLabelDoubleClick_Press(QCPAxis,QCPAxis::SelectablePart)));

-----------------------------------------------------------------------------------------

//点击曲线显示曲线参数信息

connect(ui->PressDraw, SIGNAL(plottableClick(QCPAbstractPlottable,QMouseEvent)),

this, SLOT(LineDoubleClick_Press(QCPAbstractPlottable)));

-----------------------------------------------------------------------------------------

//右键保存图像(很重要,根据设置将图像保存为自己需要的格式)

ui->PressDraw->setContextMenuPolicy(Qt::CustomContextMenu);

connect(ui->PressDraw, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(PresscontextMenuRequest(QPoint)));

//槽函数代码

void simulationPT::PresscontextMenuRequest(QPoint pos)

{

QTextCodec codec = QTextCodec::codecForName("GB18030");

QMenu menu = new QMenu(this);

menu->setAttribute(Qt::WA_DeleteOnClose);

if (ui->PressDraw->legend->selectTest(pos, false) < 0){

menu->addAction( codec->toUnicode("保存"), this, SLOT(PressSaveGraph()));

}

menu->popup(ui->PressDraw->mapToGlobal(pos));

}

-----------------------------------------------------------------------------------------

//点击右上标签编辑数据

connect(ui->PressDraw, SIGNAL(legendDoubleClick(QCPLegend,QCPAbstractLegendItem,QMouseEvent)), this,

SLOT(legendDoubleClick_Press(QCPLegend,QCPAbstractLegendItem)));

customplot点击按钮放大的 *** 作步骤如下:

1、定义一个QPushButton按钮并将其添加到窗口中。

2、在按钮的clicked()信号中添加一个槽函数。在槽函数中,可以使用QCustomPlot库提供的函数来实现放大 *** 作。

3、在槽函数中,使用QCustomPlot::rescaleAxes()函数来重新缩放图表的轴,以适应新的显示范围。

4、想要实现鼠标拖动放大的功能,可以使用QCustomPlot::setInteractions()函数来启用交互式 *** 作,并设置QCP::iRangeDrag和QCP::iRangeZoom标志来启用拖动和缩放。

MouseEvent->pos()可以获得相对于viewport()的坐标pos,

然后

size1=customPlot->viewport()size();

size2=customPlot->axisRect()->size();

pos-(size1-size2)/ 2就可以获得鼠标点击位置的坐标

MouseEvent->pos()可以获得相对于viewport()的坐标pos,

然后

size1=customPlot->viewport()size();

size2=customPlot->axisRect()->size();

pos-(size1-size2)/ 2就可以获得鼠标点击位置的坐标

以上就是关于qcustomplot 怎样设置坐标轴刻度全部的内容,包括:qcustomplot 怎样设置坐标轴刻度、qcustomplot 怎么添加标签、customplot点击按钮放大等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9595211.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-30
下一篇2023-04-30

发表评论

登录后才能评论

评论列表(0条)

    保存