简体   繁体   中英

Show points in QCustomPlot with QCPItemTracer

I am trying for a longer while now to create a mechanism that would create text labels next to my points on a plot with the coordinates. From the documentation, I have read that I need to use QCPItemTracer for that. No matter how i try, I cannot display any additional items on my plot using this object. In the QCustomPlot examples, there is one program that user QCPItemTracer, but when i run it, I also dont see any additional objects. I am trying to run the example code from 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);

From my understanding this was supposed to add red circles on my plot points. It does not. I Would really aprichiate any help in this matter, some example code maybe. I am struggling with this for a really long time.

I have managed to get the labels working:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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