c++ - 使用 QCPItemTracer 在 QCustomPlot 中显示点

标签 c++ qt label qcustomplot

我现在尝试了更长的时间来创建一种机制,该机制可以在坐标图上的点旁边创建文本标签。从文档中,我读到我需要为此使用 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;
}

关于c++ - 使用 QCPItemTracer 在 QCustomPlot 中显示点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30122534/

相关文章:

c++ - qt c++如何再次删除和添加小部件

r - 让ggplot2在顶部只写一次 Axis 标签的数量级

r - 如何使用ggplot2将 Axis 标签保留在一侧, Axis 标题保留在另一侧

c++ - 有人可以打破这条线 gcc -E -dM - </dev/null

c++ - Visual C++ 2008 问题

Qt/C++ : Icons not showing up when program is run

html - 填满 1 行上的所有内容

c++ - 比较 std::wstring 和 std::string

C++ 映射将所有键的值显示为 0

qt - 如何在 Qt 中以编程方式创建 SQLITE 数据库?