在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);