質問

I can't clear the items in a QCustomPlot. The method QCustomPlot::itemCount() always returns 0.

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

Maybe QCPItemText is not considered as an item, but how do I clear QCPItemText then? Or reset QCustomPlot?

役に立ちましたか?

解決

Use this after you allocate textLabel :

plot->addItem(textLabel); 

From the documentation :

bool QCustomPlot::addItem ( QCPAbstractItem * item)

Adds the specified item to the plot. QCustomPlot takes ownership of the item.

Returns true on success, i.e. when item wasn't already in the plot and the parent plot of item is this QCustomPlot.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top