繁体   English   中英

使用QCPItemTracer在QCustomPlot中显示点

[英]Show points in QCustomPlot with QCPItemTracer

我现在尝试了较长时间,以创建一种机制,该机制将在具有坐标的图上我的点旁边创建文本标签。 从文档中,我读到我需要为此使用QCPItemTracer。 无论我如何尝试,都无法使用此对象在地块上显示任何其他项目。 在QCustomPlot示例中,有一个用户QCPItemTracer程序,但是当我运行它时,我也看不到任何其他对象。 我试图从下面的波纹管中运行示例代码:

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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM