繁体   English   中英

QCustomPlot 添加 QCustomItemText

[英]QCustomPlot adding QCustomItemText

我正在尝试将文本项添加到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);

QcustomPlot安装路径中存在的changelog.txt文件的第 79 行,您将看到它显示为:

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

所以你不需要currentWidget->addIem(itemText)

暂无
暂无

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

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