在QcustomPlot中,给横纵坐标添加箭头的方法
//在末尾添加箭头
customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow); customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
怎么给图画虚线的方法
//设置虚线
QPen linesPen(Qt::red,1,Qt::DashLine); line = new QCPItemStraightLine(customPlot); line->setPen(linesPen); line->setClipToAxisRect(true); line->point1->setCoords(0,0); line->point2->setCoords(0,0);
//虚线平行于x轴 line->point1->setCoords(customPlot->xAxis->range().lower,0.2); line->point2->setCoords(customPlot->xAxis->range().upper,0.2);
文本框的设置
//创建文本对象
QCPItemText *text = new QCPItemText(customPlot);
//设置文本坐标解析方式 text->position->setType(QCPItemPosition::ptAxisRectRatio);
//设置位置在矩形区域的位置 text->setPositionAlignment(Qt::AlignLeft | Qt::AlignBottom);
//设置位置 text->position->setCoords(0.1,0.90);
//设置文本内容 text->setText("你好"); text->setTextAlignment(Qt::AlignLeft);
//设置颜色 text->setColor(QColor(Qt::red));
//设置页边距 text->setPadding(QMargins(1,1,1,1));
步长的设置
//创建对象
QSharedPointer<QCPAxisTickerFixed> intTicker( new QCPAxisTickerFixed );
//设置步长精度 intTicker->setTickStep(0.1);
//设置y轴步长 customPlot->yAxis->setTicker(intTicker);
设置坐标轴为矩形及坐标的刻度样式
ui->customPlot->xAxis2->setVisible(true);//x2轴可见 ui->customPlot->yAxis2->setVisible(true);//y2轴可见 ui->customPlot->xAxis2->setTicks(false);//x2刻度不可见 ui->customPlot->yAxis2->setTicks(false);//y2刻度不可见 ui->customPlot->yAxis->setSubTicks(false);//y1子刻度不可见
获取鼠标所在位置的坐标
int x_pos = e->pos().x(); int y_pos = e->pos().y(); qDebug()<<"event->pos()"<<e->pos();
鼠标坐标转化为CustomPlot内部坐标
float x_val = ui->customPlot->xAxis->pixelToCoord(x_pos); float y_val = ui->customPlot->yAxis->pixelToCoord(y_pos); qDebug()<<x_val<<y_val;
获取曲线的个数
int count = ui->customPlot->graphCount();
获取曲线上的点个数
int count = ui->customPlot->graph(0)->dataCount();
获取曲线上所有的点的x和y
QVector<double> y_data[ui->customPlot->graph(0)->dataCount()], x_data[ui->customPlot->graph(0)->dataCount()]; for (int i = 0;i < ui->customPlot->graph(k)->dataCount();i++) { float x = ui->customPlot->graph(k)->data()->at(i)->key; float y = ui->customPlot->graph(k)->data()->at(i)->value; x_data.append(x); y_data.append(y); }
QToolTip提示框
QToolTip::showText(mapToGlobal(e->pos()),QString(str),this);