0

我无法清除 a 中的项目QCustomPlot。该方法QCustomPlot::itemCount()始终返回 0。

QCustomPlot *plot = new QCustomPlot(this);
qDebug() << plot->itemCount();                    // returns 0
QCPItemText *textLabel = new QCPItemText(plot);
qDebug() << plot->itemCount();                    // returns 0

也许QCPItemText不被视为一个项目,但我该如何清除QCPItemText呢?还是重置QCustomPlot

4

1 回答 1

1

在分配 textLabel 后使用它:

plot->addItem(textLabel); 

从文档中:

bool QCustomPlot::addItem (QCPAbstractItem * 项目)

将指定的项目添加到绘图中。QCustomPlot 取得项目的所有权。

成功时返回真,即当项目尚未在绘图中并且项目的父绘图是此 QCustomPlot 时。

于 2014-01-31T22:36:23.000 回答