用qcpitemtracer在qcustomplot中显示点

Show points in QCustomPlot with QCPItemTracer

本文关键字:显示 qcustomplot qcpitemtracer      更新时间:2023-10-16

我正在尝试使用更长的时间来创建一种机制,该机制可以在与坐标的图上创建我的观点旁边的文本标签。从文档中,我读到我需要为此使用qcpitemtracer。无论我如何尝试,我都无法使用此对象在图上显示任何其他项目。在qcustomplot示例中,有一个程序用户用户qcpitemtracer,但是当我运行它时,我也看不到任何其他对象。我正在尝试从Bellow运行示例代码:

QCPItemTracer *phaseTracer = new QCPItemTracer(customPlot);
customPlot->addItem(phaseTracer);
phaseTracer->setGraph(customPlot->graph(DATA_PLOT));
phaseTracer->setGraphKey(7);
phaseTracer->setInterpolating(true);
phaseTracer->setStyle(QCPItemTracer::tsCircle);
phaseTracer->setPen(QPen(Qt::red));
phaseTracer->setBrush(Qt::red);
phaseTracer->setSize(7);

从我的理解来看,这应该在我的情节点上增加红色圆圈。它不是。在此问题上,我确实会提供任何帮助,也许是一些示例代码。我为此挣扎了很长时间。

我设法使标签正常工作:

returnCodes_t PlotData::insertPointLabel(const int& index, const double& x, const double& y)
{
    QCPItemText *textLabel = new QCPItemText(m_parentPlot);
    m_parentPlot->addItem(textLabel);
    textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
    textLabel->position->setType(QCPItemPosition::ptPlotCoords);
    textLabel->position->setCoords(x, y); // place position at center/top of axis rect
    textLabel->setText(QString("x%1 y%2").arg(x).arg(y));
    textLabel->setVisible(labelsVisible);
    m_pointLabels.insert(index, textLabel);
    return return_success;
}