Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top