QCustomPlot adding QCustomItemText

QCustomPlot adding QCustomItemText

本文关键字:QCustomItemText adding QCustomPlot      更新时间:2023-10-16

我正在尝试将文本项目添加到QCustomPlot小部件。QCPItemText构造函数将指针用于QCustomPlot小部件作为参数。

QCPItemText::QCPItemText ( QCustomPlot * parentPlot)

创建QCPItemText对象后,它可以使用成员函数QCustomPlot::addItem()添加到小部件。但是我的问题是该程序没有编译。它说没有会员功能称为QCustomPlot::addItem()。但是这个例子似乎这样做。我很困惑。

这是我的代码的一部分;

    //hash out current widget
    QCustomPlot *currentWidget = GraphWindow::dynamicWidgetHash.value(slot);
   //Setup font
    QFont plotFont;
    plotFont.setStyleHint(QFont::Helvetica);
    plotFont.setBold(true);
    plotFont.setWeight(8);
    plotFont.setPointSize(16);
    GraphWindow::setupBackground(slot);        
    QCPItemText itemText(currentWidget);
    QString dataText = "No " + xLabel + " data found. nPossibly the firm may not possess " + xLabel;
    itemText.setText(dataText);
    itemText.setPositionAlignment(Qt::AlignTop|Qt::AlignCenter);
    itemText.position->setType(QCPItemPosition::ptAxisRectRatio);
    itemText.position->setCoords(2,2);
    itemText.setFont(plotFont);
    itemText.setPen(QPen(Qt::white));

其中 dynamicWidgetHash是一个 QHash对象,它为每个给定的key存储一个QCustomPlot *

当我尝试使用此行

时发生错误

currentWidget->addIem(itemText);

changelog.txt文件中的第79行(QcustomPlot安装路径)中,您会看到它读取:

删除了QCustomPlot::addItem,现在不再需要作为项目 自动在其构造函数中注册。

因此您不需要currentWidget->addIem(itemText);